Please help me with my Visual Basic homework

eshtog

Diamond Member
Jun 7, 2001
3,449
0
0
well I am designing a program with the following

Account # Text Box
Starting Balance Text Box
Deposit Text Box
Balance Text box

then I have 3 radio buttons for account types
and some other crap thats not important

anyways I programmed all the calculations and crap but now I have a display button
which is supposed to show accnt #, bal txt box, and accnt type
for some reason I just cant get it to work
can you guys help me?

thanks in advance
 

SWScorch

Diamond Member
May 13, 2001
9,520
1
76
well, I'd really like to, but I'm afraid you're just too darn specific. Can you please be more vague? What exactly happens when you try to get it to work? Does the wrong answer show, or is nothing displayed?
 

Evadman

Administrator Emeritus<br>Elite Member
Feb 18, 2001
30,990
5
81
We are not gonna write it. Post your code and I will help.
 

eshtog

Diamond Member
Jun 7, 2001
3,449
0
0
this is what I have programmed for the display button so far

Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
MessageBox.Show(txtaccnnum.Text)


as you can sell all I have getting displayed is the account number but this is what i need it to look like

Account number: 12345678
Account Type: Savings, Checking, or Other I have these option as radio buttons in a group box called grpacct
Account Balance: $123

 

eshtog

Diamond Member
Jun 7, 2001
3,449
0
0
Evadman if you want all my coding here it is

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents btnAdd As System.Windows.Forms.Button
Friend WithEvents btnExit As System.Windows.Forms.Button
Friend WithEvents btnClear As System.Windows.Forms.Button
Friend WithEvents txtdep As System.Windows.Forms.TextBox
Friend WithEvents txtstrbal As System.Windows.Forms.TextBox
Friend WithEvents txtbal As System.Windows.Forms.TextBox
Friend WithEvents btnDisplay As System.Windows.Forms.Button
Friend WithEvents radSav As System.Windows.Forms.RadioButton
Friend WithEvents radChk As System.Windows.Forms.RadioButton
Friend WithEvents radOth As System.Windows.Forms.RadioButton
Friend WithEvents grpacct As System.Windows.Forms.GroupBox
Friend WithEvents txtaccnnum As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents Label6 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.btnAdd = New System.Windows.Forms.Button
Me.btnExit = New System.Windows.Forms.Button
Me.btnClear = New System.Windows.Forms.Button
Me.txtaccnnum = New System.Windows.Forms.TextBox
Me.txtdep = New System.Windows.Forms.TextBox
Me.txtstrbal = New System.Windows.Forms.TextBox
Me.txtbal = New System.Windows.Forms.TextBox
Me.btnDisplay = New System.Windows.Forms.Button
Me.radSav = New System.Windows.Forms.RadioButton
Me.radChk = New System.Windows.Forms.RadioButton
Me.radOth = New System.Windows.Forms.RadioButton
Me.grpacct = New System.Windows.Forms.GroupBox
Me.Label3 = New System.Windows.Forms.Label
Me.Label4 = New System.Windows.Forms.Label
Me.Label5 = New System.Windows.Forms.Label
Me.Label6 = New System.Windows.Forms.Label
Me.grpacct.SuspendLayout()
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.ForeColor = System.Drawing.Color.Red
Me.Label1.Location = New System.Drawing.Point(288, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(96, 16)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Eduard Shtogrin"
'
'Label2
'
Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.ForeColor = System.Drawing.Color.Yellow
Me.Label2.Location = New System.Drawing.Point(272, 24)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(120, 16)
Me.Label2.TabIndex = 1
Me.Label2.Text = "Assignment number 3"
'
'btnAdd
'
Me.btnAdd.Location = New System.Drawing.Point(120, 232)
Me.btnAdd.Name = "btnAdd"
Me.btnAdd.Size = New System.Drawing.Size(64, 32)
Me.btnAdd.TabIndex = 2
Me.btnAdd.Text = "Add"
'
'btnExit
'
Me.btnExit.Location = New System.Drawing.Point(16, 232)
Me.btnExit.Name = "btnExit"
Me.btnExit.Size = New System.Drawing.Size(72, 32)
Me.btnExit.TabIndex = 3
Me.btnExit.Text = "Exit"
'
'btnClear
'
Me.btnClear.Location = New System.Drawing.Point(216, 232)
Me.btnClear.Name = "btnClear"
Me.btnClear.Size = New System.Drawing.Size(64, 32)
Me.btnClear.TabIndex = 4
Me.btnClear.Text = "Clear"
'
'txtaccnnum
'
Me.txtaccnnum.Location = New System.Drawing.Point(24, 40)
Me.txtaccnnum.Name = "txtaccnnum"
Me.txtaccnnum.Size = New System.Drawing.Size(224, 20)
Me.txtaccnnum.TabIndex = 5
Me.txtaccnnum.Text = "Enter your account number"
'
'txtdep
'
Me.txtdep.Location = New System.Drawing.Point(24, 120)
Me.txtdep.Name = "txtdep"
Me.txtdep.Size = New System.Drawing.Size(224, 20)
Me.txtdep.TabIndex = 6
Me.txtdep.Text = "0"
'
'txtstrbal
'
Me.txtstrbal.Location = New System.Drawing.Point(24, 80)
Me.txtstrbal.Name = "txtstrbal"
Me.txtstrbal.Size = New System.Drawing.Size(224, 20)
Me.txtstrbal.TabIndex = 7
Me.txtstrbal.Text = "100"
'
'txtbal
'
Me.txtbal.Location = New System.Drawing.Point(24, 160)
Me.txtbal.Name = "txtbal"
Me.txtbal.Size = New System.Drawing.Size(224, 20)
Me.txtbal.TabIndex = 8
Me.txtbal.Text = ""
'
'btnDisplay
'
Me.btnDisplay.Location = New System.Drawing.Point(304, 232)
Me.btnDisplay.Name = "btnDisplay"
Me.btnDisplay.Size = New System.Drawing.Size(64, 32)
Me.btnDisplay.TabIndex = 9
Me.btnDisplay.Text = "Display"
'
'radSav
'
Me.radSav.Checked = True
Me.radSav.Location = New System.Drawing.Point(8, 16)
Me.radSav.Name = "radSav"
Me.radSav.Size = New System.Drawing.Size(64, 24)
Me.radSav.TabIndex = 11
Me.radSav.TabStop = True
Me.radSav.Text = "Savings"
'
'radChk
'
Me.radChk.Location = New System.Drawing.Point(8, 40)
Me.radChk.Name = "radChk"
Me.radChk.Size = New System.Drawing.Size(72, 24)
Me.radChk.TabIndex = 12
Me.radChk.Text = "Checking"
'
'radOth
'
Me.radOth.Location = New System.Drawing.Point(8, 64)
Me.radOth.Name = "radOth"
Me.radOth.Size = New System.Drawing.Size(56, 24)
Me.radOth.TabIndex = 13
Me.radOth.Text = "Other"
'
'grpacct
'
Me.grpacct.Controls.Add(Me.radSav)
Me.grpacct.Controls.Add(Me.radChk)
Me.grpacct.Controls.Add(Me.radOth)
Me.grpacct.Location = New System.Drawing.Point(256, 56)
Me.grpacct.Name = "grpacct"
Me.grpacct.Size = New System.Drawing.Size(112, 104)
Me.grpacct.TabIndex = 14
Me.grpacct.TabStop = False
Me.grpacct.Text = "Account type"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(24, 64)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(120, 16)
Me.Label3.TabIndex = 15
Me.Label3.Text = "Starting balance"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(24, 104)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(120, 16)
Me.Label4.TabIndex = 16
Me.Label4.Text = "Deposit amount"
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(24, 144)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(120, 16)
Me.Label5.TabIndex = 17
Me.Label5.Text = "Ending balance"
'
'Label6
'
Me.Label6.Location = New System.Drawing.Point(24, 24)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(120, 16)
Me.Label6.TabIndex = 18
Me.Label6.Text = "Your account number"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(392, 286)
Me.Controls.Add(Me.Label6)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.grpacct)
Me.Controls.Add(Me.btnDisplay)
Me.Controls.Add(Me.txtbal)
Me.Controls.Add(Me.txtstrbal)
Me.Controls.Add(Me.txtdep)
Me.Controls.Add(Me.txtaccnnum)
Me.Controls.Add(Me.btnClear)
Me.Controls.Add(Me.btnExit)
Me.Controls.Add(Me.btnAdd)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.grpacct.ResumeLayout(False)
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub

Private Sub txtdep_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtdep.TextChanged

End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtdep.Text = "0"
End Sub

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
txtbal.Text = Val(txtstrbal.Text) + Val(txtdep.Text)
End Sub

Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
MessageBox.Show(txtaccnnum.Text)

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radSav.CheckedChanged

End Sub

Private Sub RadioButton1_CheckedChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radChk.CheckedChanged

End Sub

Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grpacct.Enter

End Sub

Private Sub radOth_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radOth.CheckedChanged

End Sub
End Class
 

Evadman

Administrator Emeritus<br>Elite Member
Feb 18, 2001
30,990
5
81
Originally posted by: eshtog
this is what I have programmed for the display button so far

Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
MessageBox.Show(txtaccnnum.Text)


as you can sell all I have getting displayed is the account number but this is what i need it to look like

Account number: 12345678
Account Type: Savings, Checking, or Other I have these option as radio buttons in a group box called grpacct
Account Balance: $123

Oh, so you just don't know how to concatenate strings (add them one after another) and you also don't know about the carrage return constant

To add 2 strings together, you use the ampersand character. "&amp;". The plus sign is also valid, but it can do wierd things when you are operating on variants. So, always use an ampersand for srtings, and a plus for adding. For example, to display txtaccnnum.Text twice with an interveacing space, do this:

MessageBox.Show(txtaccnnum.Text &amp; " " &amp; txtaccnnum.Text)

To show it with no space:

MessageBox.Show(txtaccnnum.Text &amp; txtaccnnum.Text)

Now, to get the line to wrap, you need to use a constant. It is VBCrLf, and can be seen in the MSDN library, and in the object browser.

So to show txtaccnnum.Text twice, once on each line, do this:

MessageBox.Show(txtaccnnum.Text &amp; VbCrLf &amp; txtaccnnum.Text )

Want an empty line?

MessageBox.Show(txtaccnnum.Text &amp; VbCrLf &amp; VbCrLf &amp; Txtaccnnum.Text )

You should be able to figure out the rest from there. Post how you did it, and if you have any ?'s

 

eshtog

Diamond Member
Jun 7, 2001
3,449
0
0
thank you so much Evadman

now the only problem is I am trying to get the message box to show what radio button I selected in the groupbox called grpacct do you know how I do this?

also I didnt want to show the account number twice I wanted to have a label account number then the actual number like 1234, for some reason I cant figure it out

thanks in advance
 

Evadman

Administrator Emeritus<br>Elite Member
Feb 18, 2001
30,990
5
81
Originally posted by: eshtog
thank you so much Evadman

now the only problem is I am trying to get the message box to show what radio button I selected in the groupbox called grpacct do you know how I do this?

also I didnt want to show the account number twice I wanted to have a label account number then the actual number like 1234, for some reason I cant figure it out

thanks in advance

To reference another box, all you use is the <elementname>.text, and you have whatever is in the box. As for the radio boxes, check if they are true, meaning checked.

Example:

If radioboxname = true then
'raidobox is checked
messagebox "OMG! checked box!"
else
'not checked
messagebox "omg! not checked"
end if

You do not have to use the "=true", as that is the default. For example, the above code will do the same as this:

If radioboxname then
'raidobox is checked
messagebox "OMG! checked box!"
else
'not checked
messagebox "omg! not checked"
end if


If you want to add typed in text to a messagebox, just inclose it in quotes, and use the apersand "&amp;" to make it appear as one string.

messagebox("Your account number is: " &amp; txtaccnnum.Text)
 

ElFenix

Elite Member
Super Moderator
Mar 20, 2000
102,391
8,548
126
why was this above the new threads when i did a quick search for 'windows'?