Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Easy Task; Moron Programmer

ZantosZantos Member Posts: 139
I know, I've been programming in VB for almost 3 years, but this is one thing I never figured out-how to write more than one variable to a text file and then read it. Could something finally explain this to me?

ex.
[Character Stats]
Name=Mirlin
Class=Mage
Age=172
Level=61
Gold=8760
Silver=32450


And that would all be in a text file (CHAR.TXT)
I need to know how to do this for this game I'm working on, so any help would be greatly appreciated!

..:: The moron programmmer...erm...I mean Zantos ::..

Comments

  • saurabh101saurabh101 Member Posts: 41
    : I know, I've been programming in VB for almost 3 years, but this is one thing I never figured out-how to write more than one variable to a text file and then read it. Could something finally explain this to me?
    :
    : ex.
    : [Character Stats]
    : Name=Mirlin
    : Class=Mage
    : Age=172
    : Level=61
    : Gold=8760
    : Silver=32450
    :
    :
    : And that would all be in a text file (CHAR.TXT)
    : I need to know how to do this for this game I'm working on, so any help would be greatly appreciated!
    :
    : ..:: The moron programmmer...erm...I mean Zantos ::..



    You could use these API:
    [code]
    Public Declare Function GetPrivateProfileInt Lib "kernel32" _
    Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, _
    ByVal lpKeyName As String, ByVal nDefault As Long, _
    ByVal lpFileName As String) As Long

    Public Declare Function GetPrivateProfileString Lib "kernel32" _
    Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
    ByVal lpKeyName As String, ByVal lpDefault As String, _
    ByVal lpReturnedString As String, ByVal nSize As Long, _
    ByVal lpFileName As String) As Long

    Public Declare Function WritePrivateProfileString Lib "kernel32" _
    Alias "WritePrivateProfileStringA" _
    (ByVal lpApplicationName As String, ByVal lpKeyName As String, _
    ByVal lpString As String, ByVal lpFileName As String) As Long
    [/code]

    I hope this helps.

    :-D [blue][b]Saurabh[/b][/blue]
    [hr]
    Saurabh Informatics
    (Custom Software Development)
    http://saurabhinformatics.com
    http://www.saurabh.info
    [hr]

  • Pete_201Pete_201 Member Posts: 29
    : I know, I've been programming in VB for almost 3 years, but this is one thing I never figured out-how to write more than one variable to a text file and then read it. Could something finally explain this to me?
    :
    : ex.
    : [Character Stats]
    : Name=Mirlin
    : Class=Mage
    : Age=172
    : Level=61
    : Gold=8760
    : Silver=32450
    :
    :
    : And that would all be in a text file (CHAR.TXT)
    : I need to know how to do this for this game I'm working on, so any help would be greatly appreciated!
    :
    : ..:: The moron programmmer...erm...I mean Zantos ::..
    :
    Or if you can't be bothered with all that, (which I rarely can), you could do the following. Can't remember much about text files (used to using dat files now) but when I used to transfer hidden text around a network and there was multiple strings to be passed, I simply used:

    'TransferMe = String1 & "/s1/" & String2 & "/s2/" & String3 & "/s3/"...'

    Then open your file for input (or output, can't remember), and plant TransferMe

    This can then be read off with something like:
    [code]
    For i = 1 to Len(Transfer)
    StopBit = Mid(TransferMe, i, 4)
    Select Case StopBit
    Case "/s1/"
    String1 = Mid(TransferMe, 1, i - 1)
    i2 = i + 4
    Case "/s2/"
    String2 = Mid(TransferMe, i2, i - 1)
    '...and so on
    Next i
    [/code]

    It is quite a lengthy method, but it is very simple.

    However, apologies for the poor suggestion, but it is a suggestion.

    Regards,
    Tommy Long
    Business Services Team
    Barclays House, Dorset

  • judyvjudyv Member Posts: 6
    : : I know, I've been programming in VB for almost 3 years, but this is one thing I never figured out-how to write more than one variable to a text file and then read it. Could something finally explain this to me?
    : :
    : : ex.
    : : [Character Stats]
    : : Name=Mirlin
    : : Class=Mage
    : : Age=172
    : : Level=61
    : : Gold=8760
    : : Silver=32450
    : :
    : :
    : : And that would all be in a text file (CHAR.TXT)
    : : I need to know how to do this for this game I'm working on, so any help would be greatly appreciated!
    : :
    : : ..:: The moron programmmer...erm...I mean Zantos ::..
    :
    :
    :
    : You could use these API:
    : [code]
    : Public Declare Function GetPrivateProfileInt Lib "kernel32" _
    : Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, _
    : ByVal lpKeyName As String, ByVal nDefault As Long, _
    : ByVal lpFileName As String) As Long
    :
    : Public Declare Function GetPrivateProfileString Lib "kernel32" _
    : Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
    : ByVal lpKeyName As String, ByVal lpDefault As String, _
    : ByVal lpReturnedString As String, ByVal nSize As Long, _
    : ByVal lpFileName As String) As Long
    :
    : Public Declare Function WritePrivateProfileString Lib "kernel32" _
    : Alias "WritePrivateProfileStringA" _
    : (ByVal lpApplicationName As String, ByVal lpKeyName As String, _
    : ByVal lpString As String, ByVal lpFileName As String) As Long
    : [/code]
    :
    : I hope this helps.
    :
    : :-D [blue][b]Saurabh[/b][/blue]
    : [hr]
    : Saurabh Informatics
    : (Custom Software Development)
    : http://saurabhinformatics.com
    : http://www.saurabh.info
    : [hr]
    :
    I have been trying to use the GetPrivateProfileString api command and everthing seems to be working except I'm getting a blank in the returned value variable. Here is my code:

    Private Declare Function GetPrivateProfileString Lib "kernel32" _
    Alias "GetPrivateProfileStringA" (ByVal lpAppName As String, _
    ByVal lpKey As String, ByVal lpDef As String, ByVal lpValue As String, _
    ByVal lngSize As Long, ByVal lpIni As String) As Long


    Private Sub Command1_Click()

    Dim lngRtn As Long
    Dim strData As String

    strAppName = "Password Lists"
    strKey = "JUDYV"
    strDef = "***"
    intSize = 128
    strIni = "SYSTEM.INI"
    strValue = String(255, 0)

    lngRtn = GetPrivateProfileString(strAppName, strKey, strDef, strValue, _
    Len(strValue), strIni)

    MsgBox lngRtn, vbOKOnly
    strData = Left(strValue, lngRtn)
    MsgBox strData, vbOKOnly


    End Sub

    I even tried copying your declare statement into my code and it still does the same thing.

    The lngRtn value comes back as 20, which is correct for my file but the returned value string is empty.

    Can you see what I'm doing wrong?




  • paulj59paulj59 Member Posts: 420
    : : : I know, I've been programming in VB for almost 3 years, but this is one thing I never figured out-how to write more than one variable to a text file and then read it. Could something finally explain this to me?
    : : :
    : : : ex.
    : : : [Character Stats]
    : : : Name=Mirlin
    : : : Class=Mage
    : : : Age=172
    : : : Level=61
    : : : Gold=8760
    : : : Silver=32450
    : : :
    : : :
    : : : And that would all be in a text file (CHAR.TXT)
    : : : I need to know how to do this for this game I'm working on, so any help would be greatly appreciated!
    : : :
    : : : ..:: The moron programmmer...erm...I mean Zantos ::..
    : :
    : :
    : :
    : : You could use these API:
    : : [code]
    : : Public Declare Function GetPrivateProfileInt Lib "kernel32" _
    : : Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, _
    : : ByVal lpKeyName As String, ByVal nDefault As Long, _
    : : ByVal lpFileName As String) As Long
    : :
    : : Public Declare Function GetPrivateProfileString Lib "kernel32" _
    : : Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
    : : ByVal lpKeyName As String, ByVal lpDefault As String, _
    : : ByVal lpReturnedString As String, ByVal nSize As Long, _
    : : ByVal lpFileName As String) As Long
    : :
    : : Public Declare Function WritePrivateProfileString Lib "kernel32" _
    : : Alias "WritePrivateProfileStringA" _
    : : (ByVal lpApplicationName As String, ByVal lpKeyName As String, _
    : : ByVal lpString As String, ByVal lpFileName As String) As Long
    : : [/code]
    : :
    : : I hope this helps.
    : :
    : : :-D [blue][b]Saurabh[/b][/blue]
    : : [hr]
    : : Saurabh Informatics
    : : (Custom Software Development)
    : : http://saurabhinformatics.com
    : : http://www.saurabh.info
    : : [hr]
    : :
    : I have been trying to use the GetPrivateProfileString api command and everthing seems to be working except I'm getting a blank in the returned value variable. Here is my code:
    :
    : Private Declare Function GetPrivateProfileString Lib "kernel32" _
    : Alias "GetPrivateProfileStringA" (ByVal lpAppName As String, _
    : ByVal lpKey As String, ByVal lpDef As String, ByVal lpValue As String, _
    : ByVal lngSize As Long, ByVal lpIni As String) As Long
    :
    :
    : Private Sub Command1_Click()
    :
    : Dim lngRtn As Long
    : Dim strData As String
    :
    : strAppName = "Password Lists"
    : strKey = "JUDYV"
    : strDef = "***"
    : intSize = 128
    : strIni = "SYSTEM.INI"
    : strValue = String(255, 0)
    :
    : lngRtn = GetPrivateProfileString(strAppName, strKey, strDef, strValue, _
    : Len(strValue), strIni)
    :
    : MsgBox lngRtn, vbOKOnly
    : strData = Left(strValue, lngRtn)
    : MsgBox strData, vbOKOnly
    :
    :
    : End Sub
    :
    : I even tried copying your declare statement into my code and it still does the same thing.
    :
    : The lngRtn value comes back as 20, which is correct for my file but the returned value string is empty.
    :
    : Can you see what I'm doing wrong?
    :
    :
    :
    :
    :
    Is it empty, or unprintable characters.
    Try
    for l=1 to lngRtn
    debug.print asc(mid$(strValue,l,1));
    next

    If they are all still 0 then you have a problem somewhere
  • judyvjudyv Member Posts: 6
    : : : : I know, I've been programming in VB for almost 3 years, but this is one thing I never figured out-how to write more than one variable to a text file and then read it. Could something finally explain this to me?
    : : : :
    : : : : ex.
    : : : : [Character Stats]
    : : : : Name=Mirlin
    : : : : Class=Mage
    : : : : Age=172
    : : : : Level=61
    : : : : Gold=8760
    : : : : Silver=32450
    : : : :
    : : : :
    : : : : And that would all be in a text file (CHAR.TXT)
    : : : : I need to know how to do this for this game I'm working on, so any help would be greatly appreciated!
    : : : :
    : : : : ..:: The moron programmmer...erm...I mean Zantos ::..
    : : :
    : : :
    : : :
    : : : You could use these API:
    : : : [code]
    : : : Public Declare Function GetPrivateProfileInt Lib "kernel32" _
    : : : Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, _
    : : : ByVal lpKeyName As String, ByVal nDefault As Long, _
    : : : ByVal lpFileName As String) As Long
    : : :
    : : : Public Declare Function GetPrivateProfileString Lib "kernel32" _
    : : : Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
    : : : ByVal lpKeyName As String, ByVal lpDefault As String, _
    : : : ByVal lpReturnedString As String, ByVal nSize As Long, _
    : : : ByVal lpFileName As String) As Long
    : : :
    : : : Public Declare Function WritePrivateProfileString Lib "kernel32" _
    : : : Alias "WritePrivateProfileStringA" _
    : : : (ByVal lpApplicationName As String, ByVal lpKeyName As String, _
    : : : ByVal lpString As String, ByVal lpFileName As String) As Long
    : : : [/code]
    : : :
    : : : I hope this helps.
    : : :
    : : : :-D [blue][b]Saurabh[/b][/blue]
    : : : [hr]
    : : : Saurabh Informatics
    : : : (Custom Software Development)
    : : : http://saurabhinformatics.com
    : : : http://www.saurabh.info
    : : : [hr]
    : : :
    : : I have been trying to use the GetPrivateProfileString api command and everthing seems to be working except I'm getting a blank in the returned value variable. Here is my code:
    : :
    : : Private Declare Function GetPrivateProfileString Lib "kernel32" _
    : : Alias "GetPrivateProfileStringA" (ByVal lpAppName As String, _
    : : ByVal lpKey As String, ByVal lpDef As String, ByVal lpValue As String, _
    : : ByVal lngSize As Long, ByVal lpIni As String) As Long
    : :
    : :
    : : Private Sub Command1_Click()
    : :
    : : Dim lngRtn As Long
    : : Dim strData As String
    : :
    : : strAppName = "Password Lists"
    : : strKey = "JUDYV"
    : : strDef = "***"
    : : intSize = 128
    : : strIni = "SYSTEM.INI"
    : : strValue = String(255, 0)
    : :
    : : lngRtn = GetPrivateProfileString(strAppName, strKey, strDef, strValue, _
    : : Len(strValue), strIni)
    : :
    : : MsgBox lngRtn, vbOKOnly
    : : strData = Left(strValue, lngRtn)
    : : MsgBox strData, vbOKOnly
    : :
    : :
    : : End Sub
    : :
    : : I even tried copying your declare statement into my code and it still does the same thing.
    : :
    : : The lngRtn value comes back as 20, which is correct for my file but the returned value string is empty.
    : :
    : : Can you see what I'm doing wrong?
    : :
    : :
    : :
    : :
    : :
    : Is it empty, or unprintable characters.
    : Try
    : for l=1 to lngRtn
    : debug.print asc(mid$(strValue,l,1));
    : next
    :
    : If they are all still 0 then you have a problem somewhere
    :
    It was returning an empty string, but as I was stepping through the code I got to watching the way variables were processing. The strValue variable is a public variable which uses Let Property and Get Property functions to maintain it's value. I used a variable local to the subroutine and it worked like a charm.

    Thanks for your suggestion it pointed me in the right direction.

    Judy

  • Justin BibJustin Bib USAMember Posts: 0

    ________ || http://forcoder.org || free video tutorials and ebooks about || Assembly, MATLAB, Scratch, Java, JavaScript, Ruby, PHP, Swift, PL/SQL, Visual Basic, Visual Basic .NET, C++, R, C#, Perl, Go, C, Objective-C, Delphi, Python Alice, SAS, Julia, Erlang, Awk, Bash, ML, Fortran, Lisp, F#, Scheme, Kotlin, Rust, Scala, ABAP, Dart, Ada, LabVIEW, Lua, Prolog, Apex, COBOL, Crystal, FoxPro, D, Logo, Hack, VBScript, Clojure, Transact-SQL ||

Sign In or Register to comment.