VB 6 code to VBscript how to? 
Author Message
 VB 6 code to VBscript how to?

I can someone help me with that code in vb 6:

Dim NS As String, La As Long, Ca As Long, Added As Boolean, LPa As Long
NS = ""
La = -1
Open Filename For Input As 1
While Not EOF(1)
    Line Input #1, L$
    If LCase$(Mid$(L$, 1, 6)) = "[area." Then
        If Val(Mid$(L$, 7, Len(L$) - 7)) > La Then La = Val(Mid$(L$, 7,
Len(L$) - 7))
        LPa = Val(Mid$(L$, 7, Len(L$) - 7))
    End If
Wend
Close

How to convert it to VBScript?

This is what i wrote but seems there are some errors:

Set TextStream = File.OpenAsTextStream(OpenFileForReading)

While Not TextStream.AtEndOfStream
Dim L
    L=L & TextStream.ReadLine & NewLine
    If LCase(Mid(L, 1, 6)) = "[area." Then
       If Val(Mid(L, 7, Len(L) - 7)) > La Then La = Val(Mid(L, 7, Len(L) -
7))
      LPa = Val(Mid(L, 7, Len(L) - 7))
  End If
Wend



Tue, 06 Dec 2005 19:13:35 GMT  
 VB 6 code to VBscript how to?
Hi Willy

Here's my suggestion:

Dim NS As String, La As Long, Ca As Long, Added As Boolean, LPa As Long
Dim objInFile
Set objFS = CreateObject("Scripting.FileSystemObject")
NS = ""
La = -1

if objFS.FileExists(Filename) Then
    Set objInFile = objFS.OpenTextFile (strSourceFile,ForReading)
    Do While not objInFile.atEndOfStream
         L$ = objInFile.ReadLine
            If LCase$(Mid$(L$, 1, 6)) = "[area." Then
                If Val(Mid$(L$, 7, Len(L$) - 7)) > La Then La = Val(Mid$(L$,
7,Len(L$) - 7))
                LPa = Val(Mid$(L$, 7, Len(L$) - 7))
            End If
    Loop
    objInFile.Close
End If

Hope that helps.
Markus



Quote:
> I can someone help me with that code in vb 6:

> Dim NS As String, La As Long, Ca As Long, Added As Boolean, LPa As Long
> NS = ""
> La = -1
> Open Filename For Input As 1
> While Not EOF(1)
>     Line Input #1, L$
>     If LCase$(Mid$(L$, 1, 6)) = "[area." Then
>         If Val(Mid$(L$, 7, Len(L$) - 7)) > La Then La = Val(Mid$(L$, 7,
> Len(L$) - 7))
>         LPa = Val(Mid$(L$, 7, Len(L$) - 7))
>     End If
> Wend
> Close

> How to convert it to Vbscript?

> This is what i wrote but seems there are some errors:

> Set TextStream = File.OpenAsTextStream(OpenFileForReading)

> While Not TextStream.AtEndOfStream
> Dim L
>     L=L & TextStream.ReadLine & NewLine
>     If LCase(Mid(L, 1, 6)) = "[area." Then
>        If Val(Mid(L, 7, Len(L) - 7)) > La Then La = Val(Mid(L, 7, Len(L) -
> 7))
>       LPa = Val(Mid(L, 7, Len(L) - 7))
>   End If
> Wend



Tue, 06 Dec 2005 20:29:10 GMT  
 VB 6 code to VBscript how to?
You have to get rid of all the $'s, and all the "As ..." parts of the Dim
statements. vbscript only has the variant datatype.
Quote:

> Hi Willy

> Here's my suggestion:

> Dim NS As String, La As Long, Ca As Long, Added As Boolean, LPa As
> Long
> Dim objInFile
> Set objFS = CreateObject("Scripting.FileSystemObject")
> NS = ""
> La = -1

> if objFS.FileExists(Filename) Then
>     Set objInFile = objFS.OpenTextFile (strSourceFile,ForReading)
>     Do While not objInFile.atEndOfStream
>          L$ = objInFile.ReadLine
>             If LCase$(Mid$(L$, 1, 6)) = "[area." Then
>                 If Val(Mid$(L$, 7, Len(L$) - 7)) > La Then La =
> Val(Mid$(L$, 7,Len(L$) - 7))
>                 LPa = Val(Mid$(L$, 7, Len(L$) - 7))
>             End If
>     Loop
>     objInFile.Close
> End If

> Hope that helps.
> Markus



>> I can someone help me with that code in vb 6:

>> Dim NS As String, La As Long, Ca As Long, Added As Boolean, LPa As
>> Long NS = ""
>> La = -1
>> Open Filename For Input As 1
>> While Not EOF(1)
>>     Line Input #1, L$
>>     If LCase$(Mid$(L$, 1, 6)) = "[area." Then
>>         If Val(Mid$(L$, 7, Len(L$) - 7)) > La Then La = Val(Mid$(L$,
>> 7, Len(L$) - 7))
>>         LPa = Val(Mid$(L$, 7, Len(L$) - 7))
>>     End If
>> Wend
>> Close

>> How to convert it to Vbscript?

>> This is what i wrote but seems there are some errors:

>> Set TextStream = File.OpenAsTextStream(OpenFileForReading)

>> While Not TextStream.AtEndOfStream
>> Dim L
>>     L=L & TextStream.ReadLine & NewLine
>>     If LCase(Mid(L, 1, 6)) = "[area." Then
>>        If Val(Mid(L, 7, Len(L) - 7)) > La Then La = Val(Mid(L, 7,
>> Len(L) - 7))
>>       LPa = Val(Mid(L, 7, Len(L) - 7))
>>   End If
>> Wend



Tue, 06 Dec 2005 20:39:27 GMT  
 VB 6 code to VBscript how to?
I did all but the problem is in the Val , try to run the script:

Set objfso = CreateObject("Scripting.FileSystemObject")

'if objFS.FileExists(Filename) Then
    Set objInFile = objfso.OpenTextFile
("c:\scenery.cfg",OpenFileForReading)
    Do While not objInFile.atEndOfStream
         L = objInFile.ReadLine
            If LCase(Mid(L, 1, 6)) = "[area." Then
               If Val(Mid(L, 7, Len(L) - 7)) > La Then La =
Val(Mid(L,7,Len(L) - 7))
                LPa = Val(Mid(L, 7, Len(L) - 7))
            End If
    Loop
    objInFile.Close
'End If



Quote:
> You have to get rid of all the $'s, and all the "As ..." parts of the Dim
> statements. vbscript only has the variant datatype.


> > Hi Willy

> > Here's my suggestion:

> > Dim NS As String, La As Long, Ca As Long, Added As Boolean, LPa As
> > Long
> > Dim objInFile
> > Set objFS = CreateObject("Scripting.FileSystemObject")
> > NS = ""
> > La = -1

> > if objFS.FileExists(Filename) Then
> >     Set objInFile = objFS.OpenTextFile (strSourceFile,ForReading)
> >     Do While not objInFile.atEndOfStream
> >          L$ = objInFile.ReadLine
> >             If LCase$(Mid$(L$, 1, 6)) = "[area." Then
> >                 If Val(Mid$(L$, 7, Len(L$) - 7)) > La Then La =
> > Val(Mid$(L$, 7,Len(L$) - 7))
> >                 LPa = Val(Mid$(L$, 7, Len(L$) - 7))
> >             End If
> >     Loop
> >     objInFile.Close
> > End If

> > Hope that helps.
> > Markus



> >> I can someone help me with that code in vb 6:

> >> Dim NS As String, La As Long, Ca As Long, Added As Boolean, LPa As
> >> Long NS = ""
> >> La = -1
> >> Open Filename For Input As 1
> >> While Not EOF(1)
> >>     Line Input #1, L$
> >>     If LCase$(Mid$(L$, 1, 6)) = "[area." Then
> >>         If Val(Mid$(L$, 7, Len(L$) - 7)) > La Then La = Val(Mid$(L$,
> >> 7, Len(L$) - 7))
> >>         LPa = Val(Mid$(L$, 7, Len(L$) - 7))
> >>     End If
> >> Wend
> >> Close

> >> How to convert it to Vbscript?

> >> This is what i wrote but seems there are some errors:

> >> Set TextStream = File.OpenAsTextStream(OpenFileForReading)

> >> While Not TextStream.AtEndOfStream
> >> Dim L
> >>     L=L & TextStream.ReadLine & NewLine
> >>     If LCase(Mid(L, 1, 6)) = "[area." Then
> >>        If Val(Mid(L, 7, Len(L) - 7)) > La Then La = Val(Mid(L, 7,
> >> Len(L) - 7))
> >>       LPa = Val(Mid(L, 7, Len(L) - 7))
> >>   End If
> >> Wend



Tue, 06 Dec 2005 21:24:18 GMT  
 VB 6 code to VBscript how to?
Ah! I missed that!
Val() does not exist in vbscript.
http://msdn.microsoft.com/library/en-us/script56/html/vtoriFeatureInf...

You will need to write your own function to extract the number from the
string. A Google search should provide many examples:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=vbscrip...

Bob Barrows

Quote:

> I did all but the problem is in the Val , try to run the script:

> Set objfso = CreateObject("Scripting.FileSystemObject")

> 'if objFS.FileExists(Filename) Then
>     Set objInFile = objfso.OpenTextFile
> ("c:\scenery.cfg",OpenFileForReading)
>     Do While not objInFile.atEndOfStream
>          L = objInFile.ReadLine
>             If LCase(Mid(L, 1, 6)) = "[area." Then
>                If Val(Mid(L, 7, Len(L) - 7)) > La Then La =
> Val(Mid(L,7,Len(L) - 7))
>                 LPa = Val(Mid(L, 7, Len(L) - 7))
>             End If
>     Loop
>     objInFile.Close
> 'End If



>> You have to get rid of all the $'s, and all the "As ..." parts of
>> the Dim statements. vbscript only has the variant datatype.


>>> Hi Willy

>>> Here's my suggestion:

>>> Dim NS As String, La As Long, Ca As Long, Added As Boolean, LPa As
>>> Long
>>> Dim objInFile
>>> Set objFS = CreateObject("Scripting.FileSystemObject")
>>> NS = ""
>>> La = -1

>>> if objFS.FileExists(Filename) Then
>>>     Set objInFile = objFS.OpenTextFile (strSourceFile,ForReading)
>>>     Do While not objInFile.atEndOfStream
>>>          L$ = objInFile.ReadLine
>>>             If LCase$(Mid$(L$, 1, 6)) = "[area." Then
>>>                 If Val(Mid$(L$, 7, Len(L$) - 7)) > La Then La =
>>> Val(Mid$(L$, 7,Len(L$) - 7))
>>>                 LPa = Val(Mid$(L$, 7, Len(L$) - 7))
>>>             End If
>>>     Loop
>>>     objInFile.Close
>>> End If

>>> Hope that helps.
>>> Markus



>>>> I can someone help me with that code in vb 6:

>>>> Dim NS As String, La As Long, Ca As Long, Added As Boolean, LPa As
>>>> Long NS = ""
>>>> La = -1
>>>> Open Filename For Input As 1
>>>> While Not EOF(1)
>>>>     Line Input #1, L$
>>>>     If LCase$(Mid$(L$, 1, 6)) = "[area." Then
>>>>         If Val(Mid$(L$, 7, Len(L$) - 7)) > La Then La =
>>>> Val(Mid$(L$, 7, Len(L$) - 7))
>>>>         LPa = Val(Mid$(L$, 7, Len(L$) - 7))
>>>>     End If
>>>> Wend
>>>> Close

>>>> How to convert it to Vbscript?

>>>> This is what i wrote but seems there are some errors:

>>>> Set TextStream = File.OpenAsTextStream(OpenFileForReading)

>>>> While Not TextStream.AtEndOfStream
>>>> Dim L
>>>>     L=L & TextStream.ReadLine & NewLine
>>>>     If LCase(Mid(L, 1, 6)) = "[area." Then
>>>>        If Val(Mid(L, 7, Len(L) - 7)) > La Then La = Val(Mid(L, 7,
>>>> Len(L) - 7))
>>>>       LPa = Val(Mid(L, 7, Len(L) - 7))
>>>>   End If
>>>> Wend



Tue, 06 Dec 2005 21:35:44 GMT  
 VB 6 code to VBscript how to?
Tnx for the Tip, i resolved with Cint instead of Val, but trought the code
there is a Goto 1 that isn't supported by vbscript how to resolve that? this
is the code:

Set objInFile = objfso.OpenTextFile ("c:\scenery.cfg",OpenFileForReading)
    While not objInFile.atEndOfStream
   L = objInFile.ReadLine
     NS = NS + L + vbNewLine
    If Ca <= LPa And LCase(Mid(L, 1, 6)) = "[area." Then
        Ca = Cint(Mid(L, 7, Len(L) - 7))
        If LPa = Ca Then
            Added = True
           While not objInFile.atEndOfStream
    L = objInFile.ReadLine
                NS = NS + L + vbNewLine
                If L = "" Then GoTo 1
            wend

1
            NS = NS + "[Area." + GetNumber(La + 1, 3) + "]" + vbNewLine
            NS = NS + "Title=Try1" + vbNewLine
            NS = NS + "Local="  + vbNewLine
            NS = NS + "Remote=" + vbNewLine
            NS = NS + "Active=TRUE" + vbNewLine
            NS = NS + "Required=FALSE" + vbNewLine

            NS = NS + "Layer=" & La + 1 & vbNewLine
            NS = NS + vbNewLine
        End If
    End If
Wend
objInFile.Close



Quote:
> Ah! I missed that!
> Val() does not exist in vbscript.

http://msdn.microsoft.com/library/en-us/script56/html/vtoriFeatureInf...
n.asp
Quote:

> You will need to write your own function to extract the number from the
> string. A Google search should provide many examples:
> http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=vbscrip...

> Bob Barrows


> > I did all but the problem is in the Val , try to run the script:

> > Set objfso = CreateObject("Scripting.FileSystemObject")

> > 'if objFS.FileExists(Filename) Then
> >     Set objInFile = objfso.OpenTextFile
> > ("c:\scenery.cfg",OpenFileForReading)
> >     Do While not objInFile.atEndOfStream
> >          L = objInFile.ReadLine
> >             If LCase(Mid(L, 1, 6)) = "[area." Then
> >                If Val(Mid(L, 7, Len(L) - 7)) > La Then La =
> > Val(Mid(L,7,Len(L) - 7))
> >                 LPa = Val(Mid(L, 7, Len(L) - 7))
> >             End If
> >     Loop
> >     objInFile.Close
> > 'End If



> >> You have to get rid of all the $'s, and all the "As ..." parts of
> >> the Dim statements. vbscript only has the variant datatype.


> >>> Hi Willy

> >>> Here's my suggestion:

> >>> Dim NS As String, La As Long, Ca As Long, Added As Boolean, LPa As
> >>> Long
> >>> Dim objInFile
> >>> Set objFS = CreateObject("Scripting.FileSystemObject")
> >>> NS = ""
> >>> La = -1

> >>> if objFS.FileExists(Filename) Then
> >>>     Set objInFile = objFS.OpenTextFile (strSourceFile,ForReading)
> >>>     Do While not objInFile.atEndOfStream
> >>>          L$ = objInFile.ReadLine
> >>>             If LCase$(Mid$(L$, 1, 6)) = "[area." Then
> >>>                 If Val(Mid$(L$, 7, Len(L$) - 7)) > La Then La =
> >>> Val(Mid$(L$, 7,Len(L$) - 7))
> >>>                 LPa = Val(Mid$(L$, 7, Len(L$) - 7))
> >>>             End If
> >>>     Loop
> >>>     objInFile.Close
> >>> End If

> >>> Hope that helps.
> >>> Markus



> >>>> I can someone help me with that code in vb 6:

> >>>> Dim NS As String, La As Long, Ca As Long, Added As Boolean, LPa As
> >>>> Long NS = ""
> >>>> La = -1
> >>>> Open Filename For Input As 1
> >>>> While Not EOF(1)
> >>>>     Line Input #1, L$
> >>>>     If LCase$(Mid$(L$, 1, 6)) = "[area." Then
> >>>>         If Val(Mid$(L$, 7, Len(L$) - 7)) > La Then La =
> >>>> Val(Mid$(L$, 7, Len(L$) - 7))
> >>>>         LPa = Val(Mid$(L$, 7, Len(L$) - 7))
> >>>>     End If
> >>>> Wend
> >>>> Close

> >>>> How to convert it to Vbscript?

> >>>> This is what i wrote but seems there are some errors:

> >>>> Set TextStream = File.OpenAsTextStream(OpenFileForReading)

> >>>> While Not TextStream.AtEndOfStream
> >>>> Dim L
> >>>>     L=L & TextStream.ReadLine & NewLine
> >>>>     If LCase(Mid(L, 1, 6)) = "[area." Then
> >>>>        If Val(Mid(L, 7, Len(L) - 7)) > La Then La = Val(Mid(L, 7,
> >>>> Len(L) - 7))
> >>>>       LPa = Val(Mid(L, 7, Len(L) - 7))
> >>>>   End If
> >>>> Wend



Tue, 06 Dec 2005 23:03:08 GMT  
 VB 6 code to VBscript how to?
That's a silly line of code anyways. Just replace the "GoTo 1" with "exit
while". Better yet, change the loop to:

Do Until objInFile.atEndOfStream OR L = ""
    L = objInFile.ReadLine
   NS = NS + L + vbNewLine
Loop

"While ... Wend" is being phased out. It may not be supported in a future
version of vbs.

HTH,
Bob Barrows

Quote:

> Tnx for the Tip, i resolved with Cint instead of Val, but trought the
> code there is a Goto 1 that isn't supported by vbscript how to
> resolve that? this is the code:

> Set objInFile = objfso.OpenTextFile
>     ("c:\scenery.cfg",OpenFileForReading) While not
>    objInFile.atEndOfStream L = objInFile.ReadLine
>      NS = NS + L + vbNewLine
>     If Ca <= LPa And LCase(Mid(L, 1, 6)) = "[area." Then
>         Ca = Cint(Mid(L, 7, Len(L) - 7))
>         If LPa = Ca Then
>             Added = True
>            While not objInFile.atEndOfStream
>     L = objInFile.ReadLine
>                 NS = NS + L + vbNewLine
>                 If L = "" Then GoTo 1
>             wend

> 1
>             NS = NS + "[Area." + GetNumber(La + 1, 3) + "]" +
>             vbNewLine NS = NS + "Title=Try1" + vbNewLine
>             NS = NS + "Local="  + vbNewLine
>             NS = NS + "Remote=" + vbNewLine
>             NS = NS + "Active=TRUE" + vbNewLine
>             NS = NS + "Required=FALSE" + vbNewLine

>             NS = NS + "Layer=" & La + 1 & vbNewLine
>             NS = NS + vbNewLine
>         End If
>     End If
> Wend
> objInFile.Close



>> Ah! I missed that!
>> Val() does not exist in vbscript.

http://msdn.microsoft.com/library/en-us/script56/html/vtoriFeatureInf...
Quote:
> n.asp

>> You will need to write your own function to extract the number from
>> the string. A Google search should provide many examples:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=vbscrip...

- Show quoted text -

Quote:

>> Bob Barrows


>>> I did all but the problem is in the Val , try to run the script:

>>> Set objfso = CreateObject("Scripting.FileSystemObject")

>>> 'if objFS.FileExists(Filename) Then
>>>     Set objInFile = objfso.OpenTextFile
>>> ("c:\scenery.cfg",OpenFileForReading)
>>>     Do While not objInFile.atEndOfStream
>>>          L = objInFile.ReadLine
>>>             If LCase(Mid(L, 1, 6)) = "[area." Then
>>>                If Val(Mid(L, 7, Len(L) - 7)) > La Then La =
>>> Val(Mid(L,7,Len(L) - 7))
>>>                 LPa = Val(Mid(L, 7, Len(L) - 7))
>>>             End If
>>>     Loop
>>>     objInFile.Close
>>> 'End If



>>>> You have to get rid of all the $'s, and all the "As ..." parts of
>>>> the Dim statements. vbscript only has the variant datatype.


>>>>> Hi Willy

>>>>> Here's my suggestion:

>>>>> Dim NS As String, La As Long, Ca As Long, Added As Boolean, LPa As
>>>>> Long
>>>>> Dim objInFile
>>>>> Set objFS = CreateObject("Scripting.FileSystemObject")
>>>>> NS = ""
>>>>> La = -1

>>>>> if objFS.FileExists(Filename) Then
>>>>>     Set objInFile = objFS.OpenTextFile (strSourceFile,ForReading)
>>>>>     Do While not objInFile.atEndOfStream
>>>>>          L$ = objInFile.ReadLine
>>>>>             If LCase$(Mid$(L$, 1, 6)) = "[area." Then
>>>>>                 If Val(Mid$(L$, 7, Len(L$) - 7)) > La Then La =
>>>>> Val(Mid$(L$, 7,Len(L$) - 7))
>>>>>                 LPa = Val(Mid$(L$, 7, Len(L$) - 7))
>>>>>             End If
>>>>>     Loop
>>>>>     objInFile.Close
>>>>> End If

>>>>> Hope that helps.
>>>>> Markus



>>>>>> I can someone help me with that code in vb 6:

>>>>>> Dim NS As String, La As Long, Ca As Long, Added As Boolean, LPa
>>>>>> As Long NS = ""
>>>>>> La = -1
>>>>>> Open Filename For Input As 1
>>>>>> While Not EOF(1)
>>>>>>     Line Input #1, L$
>>>>>>     If LCase$(Mid$(L$, 1, 6)) = "[area." Then
>>>>>>         If Val(Mid$(L$, 7, Len(L$) - 7)) > La Then La =
>>>>>> Val(Mid$(L$, 7, Len(L$) - 7))
>>>>>>         LPa = Val(Mid$(L$, 7, Len(L$) - 7))
>>>>>>     End If
>>>>>> Wend
>>>>>> Close

>>>>>> How to convert it to Vbscript?

>>>>>> This is what i wrote but seems there are some errors:

>>>>>> Set TextStream = File.OpenAsTextStream(OpenFileForReading)

>>>>>> While Not TextStream.AtEndOfStream
>>>>>> Dim L
>>>>>>     L=L & TextStream.ReadLine & NewLine
>>>>>>     If LCase(Mid(L, 1, 6)) = "[area." Then
>>>>>>        If Val(Mid(L, 7, Len(L) - 7)) > La Then La = Val(Mid(L, 7,
>>>>>> Len(L) - 7))
>>>>>>       LPa = Val(Mid(L, 7, Len(L) - 7))
>>>>>>   End If
>>>>>> Wend



Wed, 07 Dec 2005 01:32:58 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. VB Code to VBScript

2. converting VB code to VBScript

3. Run vbscript code on VB appli

4. Converting VB code to VBScript?

5. ?Calling VBScript function in VB code

6. VBScript in the VB Code editor??

7. How to use VB code in VB Script?

8. Converting VB code to ASP code

9. Modifying Code From VB to VB Script

10. NEW VB, VBScript, ASP and VBA Source code and Controls

11. NEW VB, VBScript, ASP and VBA Source code and Controls

12. NEW VB, VBScript, ASP and VBA Source code and Controls

 

 
Powered by phpBB® Forum Software