|
I am new to vb.net and need some help, I am trying to write a program for multiplication. I need to use the next method from an object of type random to produce two positive one-digit integers, that should display a question like "How much is 6 times 7?" and type the answer in a textbox.
I want to check the answer and display a message in a label of either "correct" then ask another math question, or "Try again" in the same label and try the same math question again.
I would appreciate any help with this, I know this may not seem like a very tough task, but being new to this makes it difficult for me.
thanks, John
|
|
|
|
|
Hi; I hope you can see what I did here I left in the Windows Form Designer generated code so that you can copy/past and try.
Imports System
Imports System.Drawing
Public Class Form1
Inherits System.Windows.Forms.Form
Private firstNum As Integer
Private secondNum As Integer
Private rand As New Random ' Random number generator
Private Const msg1 As String = "How much is " ' Strings for building question
Private Const msg2 As String = " times "
Private Const msg3 As String = " Correct"
Private Const msg4 As String = " Try Again"
#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 lblQuestion As System.Windows.Forms.Label
Friend WithEvents tbAnswer As System.Windows.Forms.TextBox
Friend WithEvents cbCheckAnswer As System.Windows.Forms.Button
Friend WithEvents cbNewQuestion As System.Windows.Forms.Button
Friend WithEvents cbExit As System.Windows.Forms.Button
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.lblQuestion = New System.Windows.Forms.Label
Me.tbAnswer = New System.Windows.Forms.TextBox
Me.cbCheckAnswer = New System.Windows.Forms.Button
Me.cbNewQuestion = New System.Windows.Forms.Button
Me.cbExit = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'lblQuestion
'
Me.lblQuestion.Location = New System.Drawing.Point(16, 40)
Me.lblQuestion.Name = "lblQuestion"
Me.lblQuestion.Size = New System.Drawing.Size(248, 23)
Me.lblQuestion.TabIndex = 0
Me.lblQuestion.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'tbAnswer
'
Me.tbAnswer.Location = New System.Drawing.Point(280, 40)
Me.tbAnswer.Name = "tbAnswer"
Me.tbAnswer.Size = New System.Drawing.Size(40, 20)
Me.tbAnswer.TabIndex = 1
Me.tbAnswer.Text = ""
Me.tbAnswer.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
'
'cbCheckAnswer
'
Me.cbCheckAnswer.Location = New System.Drawing.Point(192, 80)
Me.cbCheckAnswer.Name = "cbCheckAnswer"
Me.cbCheckAnswer.Size = New System.Drawing.Size(88, 23)
Me.cbCheckAnswer.TabIndex = 2
Me.cbCheckAnswer.Text = "Check Answer"
'
'cbNewQuestion
'
Me.cbNewQuestion.Location = New System.Drawing.Point(72, 80)
Me.cbNewQuestion.Name = "cbNewQuestion"
Me.cbNewQuestion.Size = New System.Drawing.Size(80, 23)
Me.cbNewQuestion.TabIndex = 3
Me.cbNewQuestion.Text = "New Question"
'
'cbExit
'
Me.cbExit.Location = New System.Drawing.Point(128, 120)
Me.cbExit.Name = "cbExit"
Me.cbExit.TabIndex = 4
Me.cbExit.Text = "Exit"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(360, 165)
Me.Controls.Add(Me.cbExit)
Me.Controls.Add(Me.cbNewQuestion)
Me.Controls.Add(Me.cbCheckAnswer)
Me.Controls.Add(Me.tbAnswer)
Me.Controls.Add(Me.lblQuestion)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' Set up the initial question
firstNum = rand.Next(10)
secondNum = rand.Next(10)
lblQuestion.Text = msg1 & firstNum & msg2 & secondNum & _
" ?"
End Sub
Private Sub cbCheckAnswer_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cbCheckAnswer.Click
' If no data in the text box just return
If tbAnswer.Text Is Nothing Then Return
' If not a numeric value then return
If Not IsNumeric(tbAnswer.Text) Then
lblQuestion.Text = msg1 & firstNum & msg2 & secondNum & _
" ?" & msg4
Return
End If
If CInt(tbAnswer.Text.ToString) = (firstNum * secondNum) Then
' The answer was correct
lblQuestion.Text = msg1 & firstNum & msg2 & secondNum & _
" ?" & msg3
Else
' The answer was wrong
lblQuestion.Text = msg1 & firstNum & msg2 & secondNum & _
" ?" & msg4
End If
End Sub
Private Sub cbNewQuestion_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cbNewQuestion.Click
' Get a new question
firstNum = rand.Next(10)
secondNum = rand.Next(10)
lblQuestion.Text = msg1 & firstNum & msg2 & secondNum & _
" ?"
tbAnswer.Clear()
End Sub
Private Sub cbExit_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles cbExit.Click
Application.Exit()
End Sub
End Class
|
|
|
|
|
|
Despite the fact that someone has done your homework for you, you should really look over the code, work out how it works, and in future, try to do your own work and post specific questions when you get stuck.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi, I'm trying to put a user login/password on a form, and I've been searching for sample code to add this feature. I need this for a project in a week. Can anyone help?
rives
|
|
|
|
|
Here is something to get you started.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconthecookieauthenticationprovider.asp
My Blog
|
|
|
|
|
|
|
I guess this contains your answer
http://www.codeproject.com/dotnet/PrintingFormReport.asp
|
|
|
|
|
Thanks for hte reply but it not containing the answer of my question.
Actually I want to change the location of crystal report fields at run time.
i think above sentence clearing my need . if u got my idea then plz try to search some data to customize crystal report at run time.
Bundle of thanks
|
|
|
|
|
Guys,
I need to write a sfotware based on VB to print DLT barcode label.
How to start ? what should i do first?
Thanks for the help.
day88
|
|
|
|
|
search the keyword "Barcode" in articles of this group. there is an article availabe that 'll help alot
|
|
|
|
|
Hello,
I am developing database application using SQL Server. I need to use customized date format on client System. I don't want to chage the date format manually. Is there any way to chage the System Data format when I run my application via VB.NET
Thanx in Advance
|
|
|
|
|
|
I have done this but i want to change the system date as we change the system date through control panel--> Regional sttings---> date--> customize date.
its a manual way to change the system(PC) date but i want to change date formate through VB.NET code
|
|
|
|
|
Okay - All the extra information about SQL Server obviously threw me off course.
You will need to change some system registry settings. The following link tells you about settings that affect the display of the date: http://perso.wanadoo.fr/tmcd2/Country.htm#Date[^]
Be careful with this. Unless you are providing an alternative interface to the Windows Control Panel (and from what you've said you probably are not) you need to let the user know that your application will change the display date across the whole system. They will get very irritated if they find out your application is changing their date format against their wishes. If an application did this to me I would describe it as malware.
My: Blog | Photos | Next SQL Presentation
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
This is not recommended at all. One problem you'll run into is that normal users don't have to rights to change the system data format, even by poking into the regsitry. Another is if your code DOES manage to change the data format, your application must put it back when you're done. But what if your app crashes? Now the user must put the format back by hand.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
thanks to all for this appreciable advice
|
|
|
|
|
I want to send an E-mail with an attachment,but I don't install SMTP in my computer,so I have to use the System.Net.Sockets.Then I find it seems that Sockets can only send TEXT string,doesn't it? If not ,how can I send an attachment?
|
|
|
|
|
OK, ive written an App in vb.net using a sql server database. HOW DO I DEPLOY/BUILD AN INSTALL PACKAGE FOR ANOTHER COMPUTER. Please somebody, anybody, i cant find any good resources explaining what to do or anything remotely close. Please just help me atleast get started, this sucks!!!!!
|
|
|
|
|
If ur question is how to deploy a VB.NET application with sql Server then first you have to create a deployment project for your application. In deployemnt you have to add a file like DB.txt. this file must contain information about sql server name and databse name like "ServerName=ABC" and "DBName=BCD" and also userid and password if necessary. so you have to write the code to read this file and set these parameters in database connection. now you have to build the deployment prject . this 'll create setup.exe and some other files.
Now run this setup.exe on othere machine .this 'll install your application and now you have to install .NET framework and sql server on that machine.attach database to sql server
Now open the target folder of your application installed and open the file DB.txt and change the name of sql server if name is different to yours.
you can download .NET frmaework from microsoft.com (free) and also search the detail of topic "deployment project" from MSDN.
I think it'll help. if this help do tell me
|
|
|
|
|
Please show me the steps in developing a data report using visual basic 6 and access database
|
|
|
|
|
|
If I use MyBase.New in an inherited class, to call the base class's constructor will the base class's property procedures (Get/Set) verify the values passed into the constructor?
|
|
|
|