473,326 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to check textbox inputs

4
Hi I relatively new to VB.Net. And I have to create a sort of quiz type application.
There are a few Text boxes where the user will input their answers. I want the code to check the users input and compare with set answer. If correct add 1 to a total and at the end display the total correct answers. I have a code but I keep getting Errors like cannot convert boolean to integer etc. Any help please..

this is my code at the moment what is wrong?

Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
Dim TotalAns As Integer
Dim txt As Boolean

Select Case txt
Case txtRep1.Text = "A"
TotalAns += 1
Case txtRep2.Text = "B"
TotalAns += 1
End Select
txtResults.Text = Str(TotalAns)
End Sub
End Class
Mar 27 '07 #1
4 1115
shweta123
692 Expert 512MB
Hi,

Why are you taking txt as Boolean.Its not used anyway in the procedure.
Can you write the procedure like this?

Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click

Dim TotalAns As Integer
Dim txt As String

txt=txtRep1.Text

Select Case txt
Case "A"
TotalAns += 1
Case "B"
TotalAns += 1
End Select

txtResults.Text = Str(TotalAns)
End Sub
End Class
Mar 27 '07 #2
Bresy
4
Sorry about that The boolean was included as that was the error I got from the source. It said "Option Strict On disallows implicit conversions from 'Boolean' to 'String'."

Your answer works well. But only for one of the text boxes. I have 2 different text boxes at the minute and at the end I will need about 30 different user inputs.

textrep1
textrep2
textrep3 ... etc.

So I need to add one to TotalAns everytime the input matches.
I thought the select case would allow me to do this ... am I using the wrong thing?
Mar 27 '07 #3
Bresy
4
Ok Thanks a lot for your help. I have got a solution but its very long as like I said there will be 30 different inputs. So this is how I got it to work is there any other way to make this simpler.

Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click

Dim TotalAns As Integer
TotalAns = 0

If txtRep1.Text = "A" Then
TotalAns += 1
End If
If txtRep2.Text = "B" Then
TotalAns += 1
End If
If txtRep3.Text = "C" Then
TotalAns += 1
End If

txtResults.Text = Str(TotalAns)
End Sub
End Class
Mar 27 '07 #4
shweta123
692 Expert 512MB
Hi,

Are you not using Database table for storing questions and the answers?
If you use that much of your code can be reduced.You can just pass the the answer from any of your 30 textboxes to the query and you need not have to compare each with "A" ,"B" ,"C" etc.
Mar 28 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Barti | last post by:
is there any way to check if any textarea or textfield exists in current document fg function checkifexist(){ if any textarea or textfield exist return true else return false } Barti
2
by: anonieko | last post by:
This applies to javascript dynamic textbox onkey > > > Newsgroups: comp.lang.javascript From: Lasse Reichstein Nielsen <l...@hotpop.com> - Find messages by this author Date: Fri, 15 Jul 2005...
8
by: Shimrit Ben-Yair | last post by:
Hi, I'm having problems with the measureString function. I am trying to measure the length of a string the user types into a text box. However, the size in pixels that this function returns is...
28
by: kfrost | last post by:
I know this is probably simple but I have a C# form and the class for the form is called sbaSynch. I have a textbox name txtServerName. I'm creating a class to manipulate XML functions so I...
2
by: Keith Doran | last post by:
I have a webform page that contains a textbox control. The textbox is initialized by the codebehind module and contains a value when the page is first loaded. The user can then edit the textbox...
5
by: hanolo | last post by:
Does anyone ever see this happen. I build a form with couple of textbox server control. When user inputs character ` in there, after form post back, the textbox become a line of string such as...
5
by: ian | last post by:
Hi, I am currently using a Javascript function to dissallow the enter key on my ASP.NET (2.0) web page, as follows: function fnTrapKP(){ if (document.all) { if (event.keyCode == 13) {
1
by: Rich | last post by:
Hello, I have been adding a handler to the TextBox.Leave event to check if a value that is entered in a Date Textbox is a Date. This works OK. But I am just checking if there is anything...
15
by: edwire | last post by:
I'm trying to extract data from 3 textboxes to another line in the same page using the onblur command. My client inputs their 5 digit zipcode and OnBlur fills the city and state from a database...
2
by: mrutyunjaya | last post by:
hello, i have two textbox column and one button control in gridvie when i click button it will ask plese enter price in first textbox . when enter values it is asking again. how to pass...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.