?
Solved

Saving Files

Posted on 2003-03-05
4
Medium Priority
?
195 Views
Last Modified: 2010-05-01
I have this program where it calculates the stats and stuff for Dungeons and Dragons.  First you put in you race and class and then it calculates your str, dex, con, int, wis, and cha by random nuber generation and modifiers by your race and class.  I want it so it will save everything how it is.  I want it to save in a *.clc file.  Can anyone give me sample code?
0
Comment
Question by:aliendudevv
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 2

Expert Comment

by:Jacamar
ID: 8077330
I think what you are after is pretty easy, but I don't quite understand your lingo.........I am not farmiliar with D+D, but I think your problem can be easily solved.

a random number will be generated between 0 and 1, so you can get integer numbers in a range you want by doing.

Randomize

inCon = int(rnd*NumVariables+1)

NumVariables is how ever high you want the random numbers to go.

Let me know what you want to do with these numbers.
0
 
LVL 4

Expert Comment

by:RanaHossain
ID: 8078163
HI Alien,

use INI format to save the characters... of course you can call the file *.clc as you want...

for the code...

to read the variable

cHealth = ReadINI("Stats", "Character_Health", CLCFilePath)

to write.. use

WriteINI "Stats", "Character", cHealth, CLCFilePath

----------------------------------------
in a module file.. add this lines..

' declaration for read/write ini
Private 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
Private 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

'---------------------------------------------------------------------------------------
' Procedure : ReadINI
' Author    : rana
' Purpose   : reads an ini file
'---------------------------------------------------------------------------------------
Public Function ReadINI(ByVal strsection As String, ByVal strKey As String, ByVal strfullpath As String) As String
   Dim strBuffer As String
   Let strBuffer$ = String$(750, Chr$(0&))
   Let ReadINI$ = Left$(strBuffer$, GetPrivateProfileString(strsection$, ByVal LCase$(strKey$), "", strBuffer, Len(strBuffer), strfullpath$))
End Function
'---------------------------------------------------------------------------------------
' Procedure : WriteINI
' Author    : rana
' Purpose   : write to an ini file
'---------------------------------------------------------------------------------------
Public Sub WriteINI(ByVal strsection As String, ByVal strKey As String, ByVal strkeyvalue As String, ByVal strfullpath As String)
    Call WritePrivateProfileString(strsection$, UCase$(strKey$), strkeyvalue$, strfullpath$)
End Sub

0
 

Accepted Solution

by:
Jodah earned 80 total points
ID: 8085156
Try this, if oyu'd like. I've odne osmething similar. The names of controls in this code shoudl be pretty self explanatory. I AM a HUGE D&D fan, so I guess I can give ya a little something...comments included to help ya along...
///////////////////////////////////////////////////
Private Sub menuSave_Click()
'You'll need a Common Dialog control on your
'form...mine here is named "dlgMain". May have
'to add it from Project>>Components
'Call Save Dialog
    dlgMain.Flags = cdlOFNOverwritePrompt
    dlgMain.InitDir = App.Path & "\stats"
    dlgMain.FileName = ""
    dlgMain.Filter = "Stat Files (*.clc)|*.code|All Files (*.*)|*.*"
    dlgMain.DialogTitle = "Save Stats As..."
    dlgMain.ShowSave
    If Len(dlgMain.FileName) = 0 Then Exit Sub
'End Save Dialog Statistics
Open dlgMain.FileName For Output As #1
'The format of the file owudl be as follows...
'Race
'Class
'Str
'Dex
'Con
'Wis
'Int
'Cha
'For more stats, such as adding a name, add it where needed
Print #1, txtRace.Text & vbCrLf & txtClass.Text & vbCrLf & txtStr.Text & vbCrLf & txtDex.Text & vbCrLf & txtCon.Text & vbCrLf & txtWis.Text & vbCrLf & txtInt.Text & vbCrLf & txtCha.Text
Close #1
End Sub
End Sub
'The drawback to this is that each stat (*.clc) file
'must be saved individually, I.E. Your character can't be
'in the same file as oyur friend's, they're two different
'ones. If youy need a isngle writeable file, feel free to
'e-mail me, and I'd be happy to get you the code you need '
for it.
///////////////////////////////////////////////////////////
0
 

Expert Comment

by:cocomobasic
ID: 8086497
this works; lets say you have all the values you want and you have a save and load button:

' save the file
Private Sub cmdSave_Click()
Dim intFile As Integer
   
    intFile = FreeFile

    ' "c:\MyHeroStats.clc" is just an example; you should use a different file name for every character. i recommend using common dialog control

    Open "c:\MyHeroStats.clc" For Output As intFile
   
    Print #intFile, Trim(txtClass.Text)
    Print #intFile, Trim(txtDex.Text)
   
    Close intFile

End Sub

--- this will save the file as a .clc format; now for loading, do this
-----------------------------------------------------------

' load file
Private Sub cmdLoad_Click()
Dim intFile As Integer
   
Dim strClass As String
Dim strDexterity As String

    intFile = FreeFile

    ' specify the name of the character you want to load; again i recommend common dialog control    

    Open "c:\MyHeroStats.clc" For Input As intFile
   
    Input #intFile, strClass
    Input #intFile, strDexterity
   
    txtClass.Text = strClass
    txtDex.Text = strDexterity
   
    Close intFile

End Sub

' i just included two fields (class and dex) but u could add more
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 20 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question