Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error 91 - running from win98 (application written in winXP) 1

Status
Not open for further replies.

Rock4J

Programmer
Jan 14, 2013
94
0
0
MY
Hi,

I'm writing a VB6 program in Windows XP, and then I try to run the program in Windows 98.

An error #91 (Object variable or With block variable not set) appears.

here is what I write in the code:

Dim fso As Scripting.FileSystemObject 'FileSystemObject
Dim ts As TextStream
Dim tsURL As String

...

tsURL = Mid(Drive1.Drive, 1, 2) & "\brg8a.txt"
Set fso = New Scripting.FileSystemObject
If fso.FileExists(tsURL) = False Then fso.CreateTextFile tsURL
Set ts = fso_OpenTextFile(tsURL, ForWriting)

...

Could someone help me with this?

Thanks.


Regards,
Rocky
 
It would help to tell us what line you get this error on.


You might be relying on something in the Scripting Runtime that changed along the way. Windows Scripting Technologies have some major version "fault lines." Version 1.0, version 2.0 (confusingly also known as 5.1), and versions 5.2 and later are the major lines of demarcation.

If you develop on XP you either have version 5.6 or more likely 5.7, either of which should be highly compatible with version 5.8. These are the three 5.x versions in the wild today.

If you don't simply make this a target system requirement and the user's responsibility... your program's installer is supposed to conditionally install a compatible version if the target system doesn't have it. But do not try to deploy the bare scrrun.dll! There is an entire Scripting ecosystem which needs to be deployed as a package.

This package is scr56en.exe and does not seem to be available any longer. However if the user ever upgraded to IE 5.x they probably have at least 2.0/5.1 and that ought to be "good enough" most of the time.
 
Hi dilettante,

Thanks for your reply.. I cannot be sure which line because I compile exe file in XP, and the error appear when I run the exe file in Windows 98. From googling and by the error description, It look like there is "variable or with block variable not set", that's why I think it must have something to do with the Microsoft Scripting Runtime (FileSystemObject), the code that I have mentioned is just in a "Sub" for specific button. not much code there. just For...Next, ts.write, ts.writeline, if...else...endif.. that's all.. earlier there was error 430 (Class does not support Automation or does not support expected interface) too to start to program.. but I have avoid it using Error Handler..

I might try installing IE5x..

In the mean while, i'm still could use some more help.. :)

Thanks dilettante..



Regards,
Rocky
 
Hi, I just want to add some information.. Actually the code is made to write into a text file (*.txt). But since there is error #91 appears in Windows 98, the program didn't write anything at all in the text file. my customer is using windows 98 and I could not do anything about it.

Please help. :)

Regards,
Rocky
 
Here's the full code:

Code:
Private Sub cmdStart_Click()
On Error GoTo Err_Handler
    Me.MousePointer = vbHourglass
    
    Dim fso As Scripting.FileSystemObject 'FileSystemObject
    Dim ts As TextStream
    Dim tsURL As String
    
    Dim tempstr As String
    Dim strName As String
    Dim strNRIC As String
    Dim strSocso As String
    Dim missing As Integer
    
    'To prevent from processing empty records
    If MSFlexGrid1.Rows <= 1 Then
        MsgBox " No records available ", vbInformation + vbOKOnly, "Start - Prepare Diskette"
        Me.MousePointer = vbDefault
        Exit Sub
    End If
    
    tsURL = Mid(Drive1.Drive, 1, 2) & "\brg8a.txt"
    Set fso = New Scripting.FileSystemObject
    If fso.FileExists(tsURL) = False Then fso.CreateTextFile tsURL
    
    Set ts = fso.OpenTextFile(tsURL, ForWriting)
    
    For i = 1 To MSFlexGrid1.Rows - 1
            '****** Company Code ******
            ts.Write MSFlexGrid1.TextMatrix(i, 0)           'Company Code
            
            '****** NRIC Formatting ******
            tempstr = MSFlexGrid1.TextMatrix(i, 1)
            missing = 12 - Len(tempstr)
            strNRIC = Space(missing) & tempstr
            ts.Write strNRIC
            
            '****** SocsoNo Formatting ******
            tempstr = MSFlexGrid1.TextMatrix(i, 2)
            missing = 9 - Len(tempstr)
            strSocso = tempstr & Space(missing)
            ts.Write strSocso
            
            '****** Period (MonthYear) ******
            ts.Write MSFlexGrid1.TextMatrix(i, 3)
            
            '****** Name Formatting ******
            tempstr = MSFlexGrid1.TextMatrix(i, 4)
            missing = 45 - Len(tempstr)
            strName = tempstr & Space(missing)
            ts.Write strName
            
            '****** Contribution Formatting ******
            Dim ringgit As String
            Dim cents As String
            'Dim tempstr As String
            Dim cont1 As String
            Dim cont2 As String
            
            tempstr = MSFlexGrid1.TextMatrix(i, 5)
            ringgit = Mid(tempstr, 1, InStr(1, tempstr, ".", vbTextCompare) - 1)
            cents = Mid(tempstr, InStr(1, tempstr, ".", vbTextCompare) + 1, 2)
            cont1 = ringgit & cents
            If Len(cont1) < 4 Then
                If Len(cont1) = 1 Then
                    cont1 = "000" & cont1
                ElseIf Len(cont1) = 2 Then
                    cont1 = "00" & cont1
                ElseIf Len(cont1) = 3 Then
                    cont1 = "0" & cont1
                End If
            End If
            
            tempstr = MSFlexGrid1.TextMatrix(i, 6)
            ringgit = Mid(tempstr, 1, InStr(1, tempstr, ".", vbTextCompare) - 1)
            cents = Mid(tempstr, InStr(1, tempstr, ".", vbTextCompare) + 1, 2)
            cont2 = ringgit & cents
            If Len(cont2) < 4 Then
                If Len(cont2) = 1 Then
                    cont2 = "000" & cont2
                ElseIf Len(cont2) = 2 Then
                    cont2 = "00" & cont2
                ElseIf Len(cont2) = 3 Then
                    cont2 = "0" & cont2
                End If
            End If
            
            ts.Write cont1         'Employee Contribution
            ts.WriteLine cont2     'Company Contribution
    Next
    
    ts.Close
    Set ts = Nothing
    Set fso = Nothing
    
    Me.MousePointer = vbDefault
    
    MsgBox "Process completed.", vbInformation + vbOKOnly, "Process"
    
    Exit Sub
Err_Handler:
    If Err.Number = 0 Then
        Resume Next
    ElseIf Err.Number = 20 Then
        Me.MousePointer = vbDefault
        Exit Sub
    'ElseIf Err.Number = 91 Then 'Object variable or With block variable not set (appears in Windows 98)
    '    Resume Next
    ElseIf Err.Number = 430 Then 'Error on Windows 98 - Class does not support Automation or does not support expected interface
        Resume Next
    ElseIf Err.Number = 381 Then 'Runtime Error - Subscript Out of Range (This appears when running from Local hardrive)
        MsgBox " " & Err.Description & " ", vbExclamation + vbOKOnly, "ERROR: " & Err.Number
        Me.MousePointer = vbDefault
        Exit Sub
    ElseIf Err.Number = 70 Then 'Runtime Error - Permission Denied (This appears when running from Network Drive)
        MsgBox " " & Err.Description & " ", vbExclamation + vbOKOnly, "ERROR: " & Err.Number
        Me.MousePointer = vbDefault
        Exit Sub
    Else
        MsgBox " " & Err.Description & " ", vbExclamation + vbOKOnly, "ERROR: " & Err.Number
        Me.MousePointer = vbDefault
        Exit Sub
    End If
End Sub

Regards,
Rocky
 
earlier there was error 430 (Class does not support Automation or does not support expected interface) too to start to program.. but I have avoid it using Error Handler.

This sounds like something you don't want to just note and ignore. It is probably saying you have too old a version of the FSO for some operation (method, property) you are using. It could also be that the methods and properties are there but the interface is different, so you are dying because you are early-binding your FSO objects.

But that's more guessing.


You can number the lines in that subroutine and then report the hidden function [tt]Erl[/tt] in your error handler. Example:

Code:
Private Sub Command1_Click()
    Dim I As Integer, J As Integer
    
    On Error GoTo Handler
1   I = I * 2
2   J = 5 / I  '  <--- Division by Zero
3   Exit Sub
    
Handler:
    MsgBox "Error " & Err.Number & " " & Err.Description _
         & " at line " & Erl
End Sub
 
Ok, I will try to find out.. thanks dilettante.. :)

Regards,
Rocky
 
Hi agian dilettante, sorry i just want to ask you a few thing regarding the following code:
Code:
On Error GoTo Handler
1   I = I * 2
2   J = 5 / I  '  <--- Division by Zero
3   Exit Sub
Where do I need to put this code? what if i already have used I and J earlier?

Regards,
Rocky
 
With this code:

Handler:
MsgBox "Error " & Err.Number & " " & Err.Description _
& " at line " & Erl

The error #91 returned "at line 0"

Regards,
Rocky
 
That code snippet was an example.

In the procedure that is giving you trouble you already have an error handler.

By numbering all of the lines in that procedure your error handler could report the [tt]Erl[/tt] value along with [tt]Err.Number[/tt] and [tt]Err.Description[/tt] to tell you where your errors are.

If an error occurs on a line with no line number then [tt]Erl[/tt] returns 0.
 
Noted and thanks dilettante.. I will try it first..

Regards,
Rocky
 
Okay, I have already tested it and the error is at this line:

If fso.FileExists(tsURL) = False Then fso.CreateTextFile tsURL

So now, can anybody help me find out why the error#91 appears on that line?

Regards,
Rocky
 
I already solved this by installing Visual Basic 6, adding VBScript.dll in the C:\WINDOWS\System32 directory, and recompile the Project in the windows98 PC.

Hopefully this issue could be useful in the future (or may be not) for those who have to write program for Windows 98 user.

Thanks anyway. :)



Regards,
Rocky
 
So it sounds like the real issue was just as described in the first reply I posted above: the scripting components on your target system were too old to match what you compiled against.

Don't dump arbitrary things into System32 like that though. For one thing your program does not use VBScript.dll at all and for another you may easily have broken VBScript on that system now by deploying a version mismatched to the other scripting components on that system.

If anything "fixed" this it was probably installing VB6 there, which probably installed newer script components. Of course to do this you need another license for VB6 development or else this is piracy.

The correct fix is to deploy scr56en.exe onto that machine, though it is hard to come by at this late date if you never bothered to archive it yourself.

Better yet stop using the FSO except in cases where it is really necessary. It was a half-baked attempt to repurpose scripting libraries in VB6 to start a move to an object-oriented I/O model and it has these kinds of deployment headaches as well as relatively poor performance compared to VB6's native I/O statements.
 
You're probably right, but I don't think it's a big deal or issue anymore for operating system such as "WINDOWS 98".

unless there is a reliable, proper and working way how to fix the clash of the compatibilities between Windows 9x , XP, Vista/7 and 8. I guess it is the biggest mistakes ever done by Microsoft. too much changes.





Regards,
Rocky
 
>too much changes

Quite right. We should all still be using PC DOS 1.0 ... ;-)
 
Lols.. that probably right.. could PC DOS 1.0 run VB program??? XD

Regards,
Rocky
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top