Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need help with Visual basic
#1
I need help with fixing something really annoying in my visual basic code. I found some code on the internet for working with .ini files, and I wanted to incorporate it into a program that I have written. Here is the relevant part of the code.
Code:
Declare Function GetPrivateProfileString Lib "kernel32" Alias _
                 "GetPrivateProfileStringA" (ByVal lpApplicationName _
                 As String, ByVal lpKeyName As Any, ByVal lpDefault _
                 As String, ByVal lpReturnedString As String, ByVal _
                 nSize As Long, ByVal lpFileName As String) As Long
Declare Function WritePrivateProfileString Lib "kernel32" Alias _
                 "WritePrivateProfileStringA" (ByVal lpApplicationName _
                 As String, ByVal lpKeyName As Any, ByVal lpString As Any, _
                 ByVal lpFileName As String) As Long
Public Function sGetINI(sINIFile As String, sSection As String, sKey _
                As String, sDefault As String) As String
    Dim sTemp As String * 256
    Dim nLength As Integer
    sTemp = Space$(256)
    nLength = GetPrivateProfileString(sSection, sKey, sDefault, sTemp, _
              255, sINIFile)
    sGetINI = Left$(sTemp, nLength)
End Function
Public Sub writeINI(sINIFile As String, sSection As String, sKey _
           As String, sValue As String)
    Dim n As Integer
    Dim sTemp As String
    sTemp = sValue
    'Replace any CR/LF characters with spaces
    For n = 1 To Len(sValue)
        If Mid$(sValue, n, 1) = vbCr Or Mid$(sValue, n, 1) = vbLf _
        Then Mid$(sValue, n) = " "
    Next n
    n = WritePrivateProfileString(sSection, sKey, sTemp, sINIFile)
End Sub
Sub InitProgram()
Dim sINIFile As String
Dim sBetaUpdatePath As String
Dim nCount As Integer
Dim i As Integer
'Store the location of the INI file
sINIFile = App.Path & "\WAAutorun.INI"
'Read the Beta Update Path from the INI file
sBetaUpdatePath = sGetINI(sINIFile, "WAAutorun", "BetaUpdatePath", "?")
If sBetaUpdatePath = "?" Then
      'No user name was present – ask for it and save for next time
      sBetaUpdatePath = InputBox$("Enter the location of the Beta Update:")
      writeINI sINIFile, "WAAutorun", "BetaUpdatePath", sBetaUpdatePath
End If
End Sub

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
The function at the bottom is part of the code that one of you (Marshall, I think) gave to me for opening a file with its default editor. For some stupid, extremely annoying reason, it won't put the function "ShellExecute" in a separate section to the Sub defined above it, so I get an error when I try to compile.MadBang head against wall
"The present is theirs. The future, for which I really worked, is mine."
- Nikola Tesla

"My - y - my - your - my vision has permutated. My - y - my - your - my plans have followed a path unpredicted by the union of Nod and GDI. Your - my - our - our directives must be reassessed." - Kane/CABAL

[Image: 9853.png]
Reply


Messages In This Thread
I need help with Visual basic - by Professor_Tesla - 20.12.2008, 04:07:08
RE: I need help with Visual basic - by Marshall - 20.12.2008, 18:42:44
RE: I need help with Visual basic - by Marshall - 21.12.2008, 00:06:33
RE: I need help with Visual basic - by Marshall - 22.12.2008, 00:48:38
RE: I need help with Visual basic - by Marshall - 22.12.2008, 15:27:41
RE: I need help with Visual basic - by Marshall - 23.12.2008, 10:34:07
RE: I need help with Visual basic - by Marshall - 24.12.2008, 14:01:31



Users browsing this thread: 1 Guest(s)