Solved Help with VBscript error, please

Clone / X
January 13, 2018 at 17:35:50
Specs: XP SP3, AMD Ath 64X2 2GB
Help with VBscript error

Here's the error:
line 1 char 48 expected ")"

Here's the VBscript:

Private Function rtftotext(ByVal rtfstring As String) As String
Dim rtf1 As New System.Windows.Forms.RichTextBox
rtf1.Rtf = rtfstring
Return RTFToPlainText(rtf1)
End Function

Private Function RTFToPlainText(ByVal rtfbox As RichTextBox) As String
Dim str As String = String.Empty
For Each line As String In rtfbox.Lines
str += line & vbCrLf
Next
Return str
End Function

=====================

M2 Get custom script or take private lessons


See More: Help with VBscript error, please

Reply ↓  Report •

✔ Best Answer
January 26, 2018 at 06:10:21
Yeah, not helpful. You can do a 1:1 in PowerShell, but that's only useful if you've moved on to Win7 or up.
if (!([appdomain]::CurrentDomain.GetAssemblies() | ? { $_.FullName -like '*Forms,*' })) {
  Add-Type -AssemblyName System.Windows.Forms
}

$rtf = New-Object Windows.Forms.RichTextBox
$rtf.Rtf = gc "C:\Windows\System32\license.rtf"
$rtf.Text

How To Ask Questions The Smart Way

message edited by Razor2.3



#1
January 16, 2018 at 03:35:23
I'v ecopied an example double As String statement, which might help you.


Function RegexExtract(ByVal text As String, _
ByVal extract_what As String, _
Optional separator As String = ", ") As String

from:

https://stackoverflow.com/questions...

i5-6600K@4.670GHz/4.448GHz cache@1.33v | 2x4GB Crucial-DDR4-2133@ 15-15-15-31 2T 2817MHz@1.3v | ASUS Z170-K | Samsung 250GB SSD 850 EVO | MSI RX 570 4GB@1384cc&2087mc bios-powertune-mod | Corsair VS45


Reply ↓  Report •

#2
January 20, 2018 at 20:47:25
The script is meant to extract text from rtf files

=====================

M2 Get custom script or take private lessons


Reply ↓  Report •

#3
January 21, 2018 at 22:37:09
Hi m2: I kept working with the system.windows.forms.richtextbox and got nowhere. with 'dim' I got the "expected" error. tried 'createobject' and got 'activex cant create' error (I'm sure I'm doing something wrong). Best I could come up with was:
richtextfile=kri.rtf
set fso=createobject("scripting.filesystemobject")
rtfstring=fso.opentextfile(richtextfile,1).readall
p=split(rtfstring,">")
for c=0 to ubound(p)
'wscript.echo p(c)
k=split(p(c),"<")
for g=0 to ubound(k)
f=left(ltrim(k(g)),1)
' this tries to filter out some other stuff. disabled to be most inclusive
'if f <> "\" then if f <> "/"then wscript.echo k(g)
wscript.echo k(g)
next
next

message edited by nbrane


Reply ↓  Report •

Related Solutions

#4
January 21, 2018 at 23:13:36
Hi nbrane,
As Adrian Cronauer said to the guy in the truck: thank you for playing anyway

=====================

M2 Get custom script or take private lessons


Reply ↓  Report •

#5
January 25, 2018 at 09:37:39
Dim rtf1 As New System.Windows.Forms.RichTextBox

That's not VBScript. VBScript doesn't have definable types, after all. This is looking very VB.NET to me. I don't believe VBS has access to a RichTextBox, so you might have to manually parse the file. Since everything in an .rtf file is encoded in 7-bit ASCII, it shouldn't be too difficult to strip out the formatting, or to extract the required text. Mostly, you'll have to tokenize the line, and look for the various formatting key words.

How To Ask Questions The Smart Way


Reply ↓  Report •

#6
January 25, 2018 at 23:08:29
Thanks for that R2

=====================

M2 Get custom script or take private lessons


Reply ↓  Report •

#7
January 26, 2018 at 06:10:21
✔ Best Answer
Yeah, not helpful. You can do a 1:1 in PowerShell, but that's only useful if you've moved on to Win7 or up.
if (!([appdomain]::CurrentDomain.GetAssemblies() | ? { $_.FullName -like '*Forms,*' })) {
  Add-Type -AssemblyName System.Windows.Forms
}

$rtf = New-Object Windows.Forms.RichTextBox
$rtf.Rtf = gc "C:\Windows\System32\license.rtf"
$rtf.Text

How To Ask Questions The Smart Way

message edited by Razor2.3


Reply ↓  Report •

Ask Question