Results 1 to 7 of 7

Thread: [In Progress] Dumb Old RunTime Error 5

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    2

    Post [In Progress] Dumb Old RunTime Error 5

    Greetings all!

    I'm a novice at this whole Visual Basic thing so I'm trying to take a stab in the dark. I've done come C/C++ and SQL programming / scripting before so programming concepts are not completely lost on me. =-)

    I am having a problem getting a VB6 program I wrote to work in Windows 98. This little program does nothing more than allow you to launch a specific file, if found. And if no file is chosen, it will automatically launch the last file chosen.

    Here's the code thus far...

    Launcher Form
    Code:
    Dim StartTime As Integer
    Dim TimeLeft As Integer
    
    Private Sub Form_Load()
    
        Dim str4CardStartup As String * 256
        Dim str8CardStartup As String * 256
        Dim strFlashStartup As String * 256
            
        str4CardStartup = "C:\Player\MegaX\Startup.bat"
        str8CardStartup = "C:\Player\Mega8\Startup.bat"
        strFlashStartup = "C:\Player\Flash21Cash\Startup.bat"
        
        Btn4CardMega.Enabled = False
        Btn8CardMega.Enabled = False
        BtnFlashCash.Enabled = False
    
        If FileExists(str4CardStartup) Then
         Btn4CardMega.Enabled = True
        End If
        
        If FileExists(str8CardStartup) Then
         Btn8CardMega.Enabled = True
        End If
        
        If FileExists(strFlashStartup) Then
         BtnFlashCash.Enabled = True
        End If
        
        StartTime = Int(ReadIniValue(App.Path & "\launcher.ini", "Default", "Timeout"))
        TimeLeft = StartTime
        lblTimer.Caption = " " & TimeLeft & " Sec."
        LaunchTimer.Interval = 1000
        LaunchTimer.Enabled = True
    
    End Sub
            
    Public Function FileExists(sFullPath As String) As Boolean
        Dim oFile As New Scripting.FileSystemObject
        FileExists = oFile.FileExists(sFullPath)
    End Function
    
    Private Sub Btn4CardMega_Click()
        Dim str4CardStartup As String * 256
        str4CardStartup = "C:\Player\MegaX\Startup.bat"
        LaunchTimer.Enabled = False
        Shell str4CardStartup
        WriteIniValue App.Path & "\launcher.ini", "Default", "Path", "C:\Player\MegaX\Startup.bat"
    End Sub
    
    Private Sub Btn8CardMega_Click()
        Dim str8CardStartup As String * 256
        str8CardStartup = "C:\Player\Mega8\Startup.bat"
        LaunchTimer.Enabled = False
        Shell str8CardStartup
        WriteIniValue App.Path & "\launcher.ini", "Default", "Path", "C:\Player\Mega8\Startup.bat"
    End Sub
    
    Private Sub BtnFlashCash_Click()
        Dim strFlashStartup As String * 256
        strFlashStartup = "C:\Player\Flash21Cash\Startup.bat"
        LaunchTimer.Enabled = False
        Shell strFlashStartup
        WriteIniValue App.Path & "\launcher.ini", "Default", "Path", "C:\Player\Flash21Cash\Startup.bat"
    End Sub
    
    Private Sub Exit_Click()
        End
    End Sub
    
    Private Sub LaunchTimer_Timer()
        TimeLeft = TimeLeft - 1
        lblTimer.Caption = " " & TimeLeft & " Sec."
        If TimeLeft = 0 Then
            Call LaunchLast
            LaunchTimer.Enabled = False
        End If
    End Sub
    
    Private Function LaunchLast()
     Dim strLastLaunched As String * 256
     strLastLaunched = ReadIniValue(App.Path & "\launcher.ini", "Default", "Path")
     Shell strLastLaunched
     LaunchTimer.Enabled = False
    End Function
    INI Read Module
    Code:
    Option Explicit
    
    Public Function ReadIniValue(INIpath As String, KEY As String, Variable As String) As String
    Dim NF As Integer
    Dim Temp As String
    Dim LcaseTemp As String
    Dim ReadyToRead As Boolean
        
    AssignVariables:
            NF = FreeFile
            ReadIniValue = ""
            KEY = "[" & LCase$(KEY) & "]"
            Variable = LCase$(Variable)
        
    EnsureFileExists:
        Open INIpath For Binary As NF
        Close NF
        SetAttr INIpath, vbArchive
        
    LoadFile:
        Open INIpath For Input As NF
        While Not EOF(NF)
        Line Input #NF, Temp
        LcaseTemp = LCase$(Temp)
        If InStr(LcaseTemp, "[") <> 0 Then ReadyToRead = False
        If LcaseTemp = KEY Then ReadyToRead = True
        If InStr(LcaseTemp, "[") = 0 And ReadyToRead = True Then
            If InStr(LcaseTemp, Variable & "=") = 1 Then
                ReadIniValue = Mid$(Temp, 1 + Len(Variable & "="))
                Close NF: Exit Function
                End If
            End If
        Wend
        Close NF
    End Function
    INI Write Module
    Code:
    Option Explicit
    
    Public Function WriteIniValue(INIpath As String, PutKey As String, PutVariable As String, PutValue As String)
    Dim Temp As String
    Dim LcaseTemp As String
    Dim ReadKey As String
    Dim ReadVariable As String
    Dim LOKEY As Integer
    Dim HIKEY As Integer
    Dim KEYLEN As Integer
    Dim VAR As Integer
    Dim VARENDOFLINE As Integer
    Dim NF As Integer
    Dim X As Integer
    
    AssignVariables:
        NF = FreeFile
        ReadKey = vbCrLf & "[" & LCase$(PutKey) & "]" & Chr$(13)
        KEYLEN = Len(ReadKey)
        ReadVariable = Chr$(10) & LCase$(PutVariable) & "="
            
    EnsureFileExists:
        Open INIpath For Binary As NF
        Close NF
        SetAttr INIpath, vbArchive
        
    LoadFile:
        Open INIpath For Input As NF
        Temp = Input$(LOF(NF), NF)
        Temp = vbCrLf & Temp & "[]"
        Close NF
        LcaseTemp = LCase$(Temp)
        
    LogicMenu:
        LOKEY = InStr(LcaseTemp, ReadKey)
        If LOKEY = 0 Then GoTo AddKey:
        HIKEY = InStr(LOKEY + KEYLEN, LcaseTemp, "[")
        VAR = InStr(LOKEY, LcaseTemp, ReadVariable)
        If VAR > HIKEY Or VAR < LOKEY Then GoTo AddVariable:
        GoTo RenewVariable:
        
    AddKey:
            Temp = Left$(Temp, Len(Temp) - 2)
            Temp = Temp & vbCrLf & vbCrLf & "[" & PutKey & "]" & vbCrLf & PutVariable & "=" & PutValue
            GoTo TrimFinalString:
            
    AddVariable:
            Temp = Left$(Temp, Len(Temp) - 2)
            Temp = Left$(Temp, LOKEY + KEYLEN) & PutVariable & "=" & PutValue & vbCrLf & Mid$(Temp, LOKEY + KEYLEN + 1)
            GoTo TrimFinalString:
            
    RenewVariable:
            Temp = Left$(Temp, Len(Temp) - 2)
            VARENDOFLINE = InStr(VAR, Temp, Chr$(13))
            Temp = Left$(Temp, VAR) & PutVariable & "=" & PutValue & Mid$(Temp, VARENDOFLINE)
            GoTo TrimFinalString:
    
    TrimFinalString:
            Temp = Mid$(Temp, 2)
            Do Until InStr(Temp, vbCrLf & vbCrLf & vbCrLf) = 0
            Temp = Replace(Temp, vbCrLf & vbCrLf & vbCrLf, vbCrLf & vbCrLf)
            Loop
        
            Do Until Right$(Temp, 1) > Chr$(13)
            Temp = Left$(Temp, Len(Temp) - 1)
            Loop
        
            Do Until Left$(Temp, 1) > Chr$(13)
            Temp = Mid$(Temp, 2)
            Loop
        
    OutputAmendedINIFile:
            Open INIpath For Output As NF
            Print #NF, Temp
            Close NF
        
    End Function
    I'm compiling the executable on XP and moving the software to Win98. I'm thinking that might have something to do with it (I know, "DUH", right?). I would just like a 2nd set of eyes to make sure nothing is terribly messed up.

    Thanks in advance!
    -Josh
    Last edited by JoshS; Sep 21st, 2007 at 08:25 AM.

  2. #2
    Fanatic Member
    Join Date
    Jul 2007
    Location
    Essex, UK.
    Posts
    579

    Re: Dumb Old RunTime Error 5

    Hi Josh, welcome to the forums

    I've had a quick look at your code and it worked ok for me.

    Obviously I don't have the files, nor did I want you writing to my machine so I commented out the ini writing. After all error 5 is an Invalid procedure call and I would have thought that the code would have errored on my machine.

    One thing you have put the Microsoft Scripting RunTime on the 98 machine?
    Also it was only from Win 98 Second Edition that the VB runtimes were all in place as standard.

    What we do here is; if your question is answered then pull down the tab and mark it resolved. If the post was quite helpful, you might like to give it some reputation points.

    Steve.

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Dumb Old RunTime Error 5

    I'm compiling the executable on XP and moving the software to Win98. I'm thinking that might have something to do with it (I know, "DUH", right?). I would just like a 2nd set of eyes to make sure nothing is terribly messed up.
    did you make an installation package or just copy the executable?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Dumb Old RunTime Error 5

    Quote Originally Posted by westconn1
    did you make an installation package or just copy the executable?
    This is the key question.

    You can't just copy the exe. You must have an installation and setup package created, and formally install your program on ALL machines, regardless of their OS, that it will be run on.

  5. #5
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Dumb Old RunTime Error 5

    Welcome JoshS ,

    Additionaly - In VB for what it's worth; dont use End, and do away with the GoTo's.

    'End' is bad (you may have housekeeping outstanding - Objects to be released etc) - use 'Unload Me' (instead - at minimum)
    'GoTo' is bad (can difficult to follow, and not necessary) - try to restructure the Functions so you don't need to use them (GoTo is only usefull when using 'On Error' for example, not navigating Sub's / Function's)
    Last edited by Bruce Fox; Sep 21st, 2007 at 06:40 AM.

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    2

    Re: Dumb Old RunTime Error 5

    Wow, great things to look into! Thanks for all the help, everyone!

    So far I have just copied the executable and I did not create an install package. How would one go about doing that?

    This program is for high-volume deployment on secure win98 machines (by secure I mean behind lock and key in a cabinet) so the install package needs to be unassisted.

    I will be updating the code to take out the "bad" code. Will report back with updates.

    Thanks!
    -JoshS

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Dumb Old RunTime Error 5

    Quote Originally Posted by JoshS
    So far I have just copied the executable and I did not create an install package. How would one go about doing that?
    Either use the Package and Deployment Wizard that comes with VB, or something like Inno.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width