Results 1 to 7 of 7

Thread: [In Progress] Dumb Old RunTime Error 5

Threaded View

  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.

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