Forms in VB

Almost got it

  • (2 Pages)
  • +
  • 1
  • 2

24 Replies - 1643 Views - Last Post: 23 March 2010 - 05:45 AM Rate Topic: -----

#1 jamminjamin55  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 38
  • Joined: 12-March 10

Forms in VB

Posted 22 March 2010 - 01:04 PM

I almost have it complete but have a couple of errors. Can someone please be kind enough to tell me what I am doing wrong? I've been at this for days and am so close. I also appreciate all of you who have been coaching me through these tutorials you're great. I posted a photo of my actual form and code and it shows my errors. Any help would keep me from pulling my hair out.

Thanx Yall.

This post has been edited by jamminjamin55: 22 March 2010 - 03:52 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Forms in VB

#2 bflosabre91  Icon User is offline

  • go sabres

Reputation: 105
  • View blog
  • Posts: 1,439
  • Joined: 22-February 08

Re: Forms in VB

Posted 22 March 2010 - 01:21 PM

ur not using the if, ifelse, end if correctly. the way u have it set up there, u are missing an end if before the second if. it would be alot easier if you copied and pasted your code instead of posting a screenshot so i can show you exactly where im talking about.
Was This Post Helpful? 1
  • +
  • -

#3 snikmotnairb  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 70
  • Joined: 02-May 08

Re: Forms in VB

Posted 22 March 2010 - 02:13 PM

You're almost there, but as Sabre said, your If Else statements aren't written exactly right, also, you'll need another variable defined to hold your answer as shown below.

This should do what you need:

Dim txtOutput As String = String.Empty

if StudentAge < 21 Then

   If StuQuietRequest = "Y" Then

       txtOutput = "Addams"

   Else If StuQuietRequest = "N" Then

       txtOutput = "Grant"
   
   End if
	
Else If StudentAge > 21 Then

   txtOutput = "Lincoln" (it doesn't matter if they pick Y or N because the only option is Lincoln)

End If

btnResults.Text = txtOutput



Also, as Sabre said, please post your actual code rather than screenshots as it makes it easier for people to edit/fix the problems you are having.
Was This Post Helpful? 1
  • +
  • -

#4 jamminjamin55  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 38
  • Joined: 12-March 10

Re: Forms in VB

Posted 22 March 2010 - 02:50 PM

So I applied your code and changed the names to match mine and it worked mostly. When I hit the button it executes the answer but displays it on the actual button and not in the txtOutput box. How do I make the answer appear in the txtOutputbox? Here is my code

Public Class Form1

    Private Sub btnResults_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResults.Click
        ' calculate which student(s) want a quiet Hall
       

        Dim txtOutput As String = String.Empty

        If txtStudentAge.Text < 21 Then

            If txtStuQuietRequest.Text = "Y" Then

                txtOutput = "Addams"

            ElseIf txtStuQuietRequest.Text = "N" Then

                txtOutput = "Grant"

            End If

        ElseIf txtStudentAge.Text > 21 Then

            txtOutput = "Lincoln"

        End If

        btnResults.Text = txtOutput

    End Sub

End Class





Thank you so much in advance.

Admin Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)
Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Forms in VB

Posted 22 March 2010 - 02:54 PM

You're kidding right?! You simply change this line

btnResults.Text = txtOutput



To

txtOutputbox.Text = txtOutput


Was This Post Helpful? 1
  • +
  • -

#6 jamminjamin55  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 38
  • Joined: 12-March 10

Re: Forms in VB

Posted 22 March 2010 - 03:01 PM

You see I tried that already and it told me that Error 'Text' is not a member of 'String' That is why I asked. I am sorry for all of the dumb questions I've only been at this for a couple of weeks and am trying to learn VB, really want to learn to program but my spare time is limited. Sorry for being a New DIC HEAD.
Was This Post Helpful? 0
  • +
  • -

#7 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Forms in VB

Posted 22 March 2010 - 03:03 PM

Let's see your code then. It seems you have a variable named txtOutputbox along with having a TextBox named that as well?
Was This Post Helpful? 1
  • +
  • -

#8 jamminjamin55  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 38
  • Joined: 12-March 10

Re: Forms in VB

Posted 22 March 2010 - 03:10 PM

Public Class Form1

Private Sub btnResults_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResults.Click
' calculate which student(s) want a quiet Hall


Dim txtOutput As String = String.Empty

If txtStudentAge.Text < 21 Then

If txtStuQuietRequest.Text = "Y" Then

txtOutput = "Addams"

ElseIf txtStuQuietRequest.Text = "N" Then

txtOutput = "Grant"

End If

ElseIf txtStudentAge.Text > 21 Then

txtOutput = "Lincoln"

End If

txtOutput.Text = txtOutput

End Sub

End Class



Thank you
Was This Post Helpful? 0
  • +
  • -

#9 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Forms in VB

Posted 22 March 2010 - 03:26 PM

What is the name of the textbox located at the bottom of your form you showed in the original post?
Was This Post Helpful? 1
  • +
  • -

#10 jamminjamin55  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 38
  • Joined: 12-March 10

Re: Forms in VB

Posted 22 March 2010 - 03:45 PM

An introduction to Programming using Visual Basic 2008, I checked it out from my public library about 2 weeks ago. I found it on Amazon http://www.amazon.co...8/dp/0136060722 and was thinking about buying it. Do you have any recommendations on what books are better if any?
The book is kind of vague and I've been reading up on text boxes, strings etc... but have been doing mostly tutorials that I find online. The project I am working on is a tutorial that someone sent me and I've been trying to figure it out. He thought it would help me learn Forms stuff but I'm all confused.

This post has been edited by jamminjamin55: 22 March 2010 - 03:49 PM

Was This Post Helpful? 0
  • +
  • -

#11 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Forms in VB

Posted 22 March 2010 - 03:51 PM

LOL, the name of the TEXTBOX not TEXTBOOK :D
Was This Post Helpful? 1
  • +
  • -

#12 jamminjamin55  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 38
  • Joined: 12-March 10

Re: Forms in VB

Posted 22 March 2010 - 03:56 PM

txtOutput is the name of the textbox...Duh I'm a retard sorry I miss understood you. This is my original code I started with but someone helped me modify it. I really want to stick with this code if I can because this is what the book shows. Doesn't really matter to me though, I just want it to work and since I am in-experienced I though I would ask the Pros.

Here is my complete code. I clicked on everything so that the names would appear if this helps.

Public Class Form1

Private Sub btnResults_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResults.Click
' calculate which student(s) want a quiet Hall
Dim StudentAge, StuQuietRequest, Output As Integer

StudentAge = txtStudentAge.Text

StuQuietRequest = txtStuQuietRequest.Text

Output = StudentAge & StuQuietRequest

If (StudentAge < 21) Then If StuQuietRequest = "Y" Or StuQuietRequest = "N" Then
If ("Y" = "Addams") & ("N" = "Grant") Then

If (StudentAge > 21) Then If StuQuietRequest = "Y" Or StuQuietRequest = "N" Then
If ("Y" = "Lincoln") & ("N" = "Lincoln") Then

End If

End If
btnResults.Text = txtOutput.Text = StudentAge & StuQuietRequest & Output

End Sub

Private Sub lblAge_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblAge.Click

End Sub

Private Sub txtStudentAge_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStudentAge.TextChanged

End Sub

Private Sub lblYesNo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblYesNo.Click

End Sub

Private Sub txtStuQuietRequest_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStuQuietRequest.TextChanged

End Sub

Private Sub txtOutput_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtOutput.TextChanged

End Sub
End Class



I'm trying to learn the WAP programming language also, do you know anything about that? I think it would be cool to write my own aps.

Thanks again for helping out a NOOB :)

This post has been edited by jamminjamin55: 22 March 2010 - 03:59 PM

Was This Post Helpful? 0
  • +
  • -

#13 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Forms in VB

Posted 22 March 2010 - 03:56 PM

No problem.
Anyway, the problem is exactly what PsychoCoder stated above. You have declared a variable of type string with the same name as your textbox object.

You have two choices, rename the string variable to something else, which means you will have to work down the code and change it wherever it is used. Or the more simpler way would be to rename the textbox to something like txtResult

Then you can put at the bottom of your code txtResult.Text = txtOutput
Was This Post Helpful? 1
  • +
  • -

#14 jamminjamin55  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 38
  • Joined: 12-March 10

Re: Forms in VB

Posted 22 March 2010 - 04:00 PM

I'll try it bro thank you.
Was This Post Helpful? 0
  • +
  • -

#15 jamminjamin55  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 38
  • Joined: 12-March 10

Re: Forms in VB

Posted 22 March 2010 - 04:11 PM

Thanks for all of your help. I'm still getting errors and I don't want to take up all of your time. Here is the code from Psycho Coder

Public Class Form1

Private Sub btnResults_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResults.Click
' calculate which student(s) want a quiet Hall


Dim txtResults As String = String.Empty

If txtStudentAge.Text < 21 Then

If txtStuQuietRequest.Text = "Y" Then

txtResults = "Addams"

ElseIf txtStuQuietRequest.Text = "N" Then

txtResults = "Grant"

End If

ElseIf txtStudentAge.Text > 21 Then

txtResults = "Lincoln"

End If

txtResults.Text = txtOutput

End Sub

Private Sub txtStudentAge_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStudentAge.TextChanged

End Sub

Private Sub txtStuQuietRequest_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStuQuietRequest.TextChanged

End Sub

Private Sub txtResult_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtResult.TextChanged

End Sub
End Class


I tried making the modifications that you suggested but am not having any luck. Man it's so frustrating trying to learn something new, but I'll get it.

This post has been edited by jamminjamin55: 22 March 2010 - 04:13 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2