home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Game Programming for Teens / VBGPFT.cdr / sources / chapter15 / CharacterEditor / Form1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2004-10-24  |  11.9 KB  |  403 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Simple Character Editor"
  5.    ClientHeight    =   6330
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   6660
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    ScaleHeight     =   422
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   444
  14.    StartUpPosition =   3  'Windows Default
  15.    Begin VB.TextBox txtLevel 
  16.       Height          =   375
  17.       Left            =   5280
  18.       TabIndex        =   8
  19.       Top             =   1800
  20.       Width           =   1095
  21.    End
  22.    Begin VB.TextBox txtExp 
  23.       Height          =   375
  24.       Left            =   5280
  25.       TabIndex        =   7
  26.       Top             =   1320
  27.       Width           =   1095
  28.    End
  29.    Begin VB.TextBox txtSta 
  30.       Height          =   375
  31.       Left            =   1920
  32.       TabIndex        =   6
  33.       Top             =   3240
  34.       Width           =   1095
  35.    End
  36.    Begin VB.CommandButton Command1 
  37.       Caption         =   "RESET"
  38.       Height          =   495
  39.       Left            =   240
  40.       TabIndex        =   18
  41.       Top             =   5280
  42.       Width           =   1215
  43.    End
  44.    Begin VB.TextBox txtFilename 
  45.       Height          =   405
  46.       Left            =   1920
  47.       TabIndex        =   16
  48.       Top             =   4440
  49.       Width           =   3495
  50.    End
  51.    Begin VB.ComboBox cboClass 
  52.       Height          =   315
  53.       ItemData        =   "Form1.frx":0000
  54.       Left            =   1920
  55.       List            =   "Form1.frx":0013
  56.       TabIndex        =   1
  57.       Text            =   "Combo1"
  58.       Top             =   720
  59.       Width           =   2415
  60.    End
  61.    Begin VB.TextBox txtCha 
  62.       Height          =   375
  63.       Left            =   1920
  64.       TabIndex        =   5
  65.       Top             =   2760
  66.       Width           =   1095
  67.    End
  68.    Begin VB.TextBox txtInt 
  69.       Height          =   375
  70.       Left            =   1920
  71.       TabIndex        =   4
  72.       Top             =   2280
  73.       Width           =   1095
  74.    End
  75.    Begin VB.TextBox txtDex 
  76.       Height          =   375
  77.       Left            =   1920
  78.       TabIndex        =   3
  79.       Top             =   1800
  80.       Width           =   1095
  81.    End
  82.    Begin VB.TextBox txtStr 
  83.       Height          =   375
  84.       Left            =   1920
  85.       TabIndex        =   2
  86.       Top             =   1320
  87.       Width           =   1095
  88.    End
  89.    Begin VB.CommandButton cmdSave 
  90.       Caption         =   "SAVE"
  91.       Height          =   495
  92.       Left            =   4920
  93.       TabIndex        =   22
  94.       Top             =   5280
  95.       Width           =   1215
  96.    End
  97.    Begin VB.CommandButton cmdLoad 
  98.       Caption         =   "LOAD"
  99.       Height          =   495
  100.       Left            =   3240
  101.       TabIndex        =   21
  102.       Top             =   5280
  103.       Width           =   1215
  104.    End
  105.    Begin VB.TextBox txtName 
  106.       Height          =   375
  107.       Left            =   1920
  108.       TabIndex        =   0
  109.       Top             =   240
  110.       Width           =   3495
  111.    End
  112.    Begin VB.Label Label10 
  113.       Caption         =   "LEVEL:"
  114.       BeginProperty Font 
  115.          Name            =   "Arial"
  116.          Size            =   9.75
  117.          Charset         =   0
  118.          Weight          =   700
  119.          Underline       =   0   'False
  120.          Italic          =   0   'False
  121.          Strikethrough   =   0   'False
  122.       EndProperty
  123.       Height          =   255
  124.       Left            =   3480
  125.       TabIndex        =   20
  126.       Top             =   1800
  127.       Width           =   1215
  128.    End
  129.    Begin VB.Label Label9 
  130.       Caption         =   "EXPERIENCE:"
  131.       BeginProperty Font 
  132.          Name            =   "Arial"
  133.          Size            =   9.75
  134.          Charset         =   0
  135.          Weight          =   700
  136.          Underline       =   0   'False
  137.          Italic          =   0   'False
  138.          Strikethrough   =   0   'False
  139.       EndProperty
  140.       Height          =   255
  141.       Left            =   3480
  142.       TabIndex        =   19
  143.       Top             =   1320
  144.       Width           =   1455
  145.    End
  146.    Begin VB.Label Label8 
  147.       Caption         =   "FILENAME:"
  148.       BeginProperty Font 
  149.          Name            =   "Arial"
  150.          Size            =   9.75
  151.          Charset         =   0
  152.          Weight          =   700
  153.          Underline       =   0   'False
  154.          Italic          =   0   'False
  155.          Strikethrough   =   0   'False
  156.       EndProperty
  157.       Height          =   255
  158.       Left            =   240
  159.       TabIndex        =   17
  160.       Top             =   4440
  161.       Width           =   1215
  162.    End
  163.    Begin VB.Label Label7 
  164.       Caption         =   "CLASS:"
  165.       BeginProperty Font 
  166.          Name            =   "Arial"
  167.          Size            =   9.75
  168.          Charset         =   0
  169.          Weight          =   700
  170.          Underline       =   0   'False
  171.          Italic          =   0   'False
  172.          Strikethrough   =   0   'False
  173.       EndProperty
  174.       Height          =   255
  175.       Left            =   240
  176.       TabIndex        =   15
  177.       Top             =   840
  178.       Width           =   1215
  179.    End
  180.    Begin VB.Label Label6 
  181.       Caption         =   "STAMINA:"
  182.       BeginProperty Font 
  183.          Name            =   "Arial"
  184.          Size            =   9.75
  185.          Charset         =   0
  186.          Weight          =   700
  187.          Underline       =   0   'False
  188.          Italic          =   0   'False
  189.          Strikethrough   =   0   'False
  190.       EndProperty
  191.       Height          =   255
  192.       Left            =   240
  193.       TabIndex        =   14
  194.       Top             =   3240
  195.       Width           =   1215
  196.    End
  197.    Begin VB.Label Label5 
  198.       Caption         =   "CHARISMA:"
  199.       BeginProperty Font 
  200.          Name            =   "Arial"
  201.          Size            =   9.75
  202.          Charset         =   0
  203.          Weight          =   700
  204.          Underline       =   0   'False
  205.          Italic          =   0   'False
  206.          Strikethrough   =   0   'False
  207.       EndProperty
  208.       Height          =   255
  209.       Left            =   240
  210.       TabIndex        =   13
  211.       Top             =   2760
  212.       Width           =   1215
  213.    End
  214.    Begin VB.Label Label4 
  215.       Caption         =   "INTELLECT:"
  216.       BeginProperty Font 
  217.          Name            =   "Arial"
  218.          Size            =   9.75
  219.          Charset         =   0
  220.          Weight          =   700
  221.          Underline       =   0   'False
  222.          Italic          =   0   'False
  223.          Strikethrough   =   0   'False
  224.       EndProperty
  225.       Height          =   255
  226.       Left            =   240
  227.       TabIndex        =   12
  228.       Top             =   2280
  229.       Width           =   1215
  230.    End
  231.    Begin VB.Label Label3 
  232.       Caption         =   "DEXTERITY:"
  233.       BeginProperty Font 
  234.          Name            =   "Arial"
  235.          Size            =   9.75
  236.          Charset         =   0
  237.          Weight          =   700
  238.          Underline       =   0   'False
  239.          Italic          =   0   'False
  240.          Strikethrough   =   0   'False
  241.       EndProperty
  242.       Height          =   255
  243.       Left            =   240
  244.       TabIndex        =   11
  245.       Top             =   1800
  246.       Width           =   1215
  247.    End
  248.    Begin VB.Label Label2 
  249.       Caption         =   "STRENGTH:"
  250.       BeginProperty Font 
  251.          Name            =   "Arial"
  252.          Size            =   9.75
  253.          Charset         =   0
  254.          Weight          =   700
  255.          Underline       =   0   'False
  256.          Italic          =   0   'False
  257.          Strikethrough   =   0   'False
  258.       EndProperty
  259.       Height          =   255
  260.       Left            =   240
  261.       TabIndex        =   10
  262.       Top             =   1320
  263.       Width           =   1215
  264.    End
  265.    Begin VB.Label Label1 
  266.       Caption         =   "NAME:"
  267.       BeginProperty Font 
  268.          Name            =   "Arial"
  269.          Size            =   9.75
  270.          Charset         =   0
  271.          Weight          =   700
  272.          Underline       =   0   'False
  273.          Italic          =   0   'False
  274.          Strikethrough   =   0   'False
  275.       EndProperty
  276.       Height          =   255
  277.       Left            =   240
  278.       TabIndex        =   9
  279.       Top             =   240
  280.       Width           =   1215
  281.    End
  282. Attribute VB_Name = "Form1"
  283. Attribute VB_GlobalNameSpace = False
  284. Attribute VB_Creatable = False
  285. Attribute VB_PredeclaredId = True
  286. Attribute VB_Exposed = False
  287. '---------------------------------------------------------------
  288. ' Visual Basic Game Programming for Teens
  289. ' Character Editor Program
  290. '---------------------------------------------------------------
  291. Option Explicit
  292. Option Base 0
  293. Private Type TCHARACTER
  294.     name As String * 20
  295.     classtype As String * 20
  296.     experience As Integer
  297.     level As Integer
  298.     strength As Integer
  299.     dexterity As Integer
  300.     intellect  As Integer
  301.     charisma As Integer
  302.     stamina As Integer
  303.     fillerstr As String * 80
  304.     fillerint(10) As Integer
  305. End Type
  306. Dim Player As TCHARACTER
  307. Private Sub cmdLoad_Click()
  308.     Player = LoadCharacterBinaryFile(txtFilename.Text)
  309.     With Player
  310.         txtName.Text = Trim(.name)
  311.         cboClass.Text = Trim(.classtype)
  312.         txtStr.Text = Trim(.strength)
  313.         txtDex.Text = .dexterity
  314.         txtInt.Text = .intellect
  315.         txtCha.Text = .charisma
  316.         txtSta.Text = .stamina
  317.         txtExp.Text = .experience
  318.         txtLevel.Text = .level
  319.     End With
  320. End Sub
  321. Private Sub Command1_Click()
  322.     txtName.Text = ""
  323.     cboClass.ListIndex = -1
  324.     txtStr.Text = ""
  325.     txtDex.Text = ""
  326.     txtInt.Text = ""
  327.     txtCha.Text = ""
  328.     txtSta.Text = ""
  329.     txtExp.Text = ""
  330.     txtLevel.Text = ""
  331. End Sub
  332. Private Sub cmdSave_Click()
  333.     Player.name = txtName.Text
  334.     Player.classtype = cboClass.Text
  335.     If IsNumeric(txtStr.Text) Then
  336.         Player.strength = CInt(txtStr.Text)
  337.     Else
  338.         MsgBox "Strength must be numeric"
  339.         Exit Sub
  340.     End If
  341.     If IsNumeric(txtDex.Text) Then
  342.         Player.dexterity = CInt(txtDex.Text)
  343.     Else
  344.         MsgBox "Dexterity must be numeric"
  345.         Exit Sub
  346.     End If
  347.     If IsNumeric(txtInt.Text) Then
  348.         Player.intellect = CInt(txtInt.Text)
  349.     Else
  350.         MsgBox "Intellect must be numeric"
  351.         Exit Sub
  352.     End If
  353.     If IsNumeric(txtCha.Text) Then
  354.         Player.charisma = CInt(txtCha.Text)
  355.     Else
  356.         MsgBox "Charisma must be numeric"
  357.         Exit Sub
  358.     End If
  359.     If IsNumeric(txtSta.Text) Then
  360.         Player.stamina = CInt(txtSta.Text)
  361.     Else
  362.         MsgBox "Stamina must be numeric"
  363.         Exit Sub
  364.     End If
  365.     If IsNumeric(txtExp.Text) Then
  366.         Player.experience = CInt(txtExp.Text)
  367.     Else
  368.         MsgBox "Experience must be numeric"
  369.         Exit Sub
  370.     End If
  371.     If IsNumeric(txtLevel.Text) Then
  372.         Player.level = CInt(txtLevel.Text)
  373.     Else
  374.         MsgBox "Level must be numeric"
  375.         Exit Sub
  376.     End If
  377.     SaveCharacterBinaryFile txtFilename.Text, Player
  378. End Sub
  379. Private Function LoadCharacterBinaryFile(ByVal filename As String) As TCHARACTER
  380.     On Error GoTo error1
  381.     Dim filenum As Integer
  382.     Dim dude As TCHARACTER
  383.     filenum = FreeFile()
  384.     Open filename For Binary As filenum Len = Len(dude)
  385.     Get filenum, , dude
  386.     Close filenum
  387.     LoadCharacterBinaryFile = dude
  388.     Exit Function
  389. error1:
  390.     MsgBox Err.Description
  391. End Function
  392. Private Function SaveCharacterBinaryFile(ByVal filename As String, ByRef dude As TCHARACTER)
  393.     On Error GoTo error1
  394.     Dim filenum As Integer
  395.     filenum = FreeFile()
  396.     Open filename For Binary As filenum Len = Len(dude)
  397.     Put filenum, , dude
  398.     Close filenum
  399.     Exit Function
  400. error1:
  401.     MsgBox Err.Description
  402. End Function
  403.