|
Thanks for the reply,
When I add the case statments the app gets stuck in the loop for some reason. There are no error messages. The program will not display the "guess higher" or "guess lower". In addition it will not perform its data validation. It just keeps displaying the inputBox. I thought maybe I coded the event arguement for the Cancel and OK incorretly, but I cant find anything in my book(Microsoft Visual Basic 2005: Reloaded, Second Edition).
I apoligize for th sloppy code. I have been hash at it for the last week. I even toyed with methods of input(listbox and combobox). The input box just facilitates input for a Loop. My frustration maybe getting the better of me.
The code works as is, but when I hit the cancel button from the input box I keep getting the data validation message, which prompted me to use the case statement.
|
|
|
|
|
I think I understand what is wrong here but please let me know if my guess about your intentions is incorrect.
It looks like you're drawing a false analogee between how c/c++ handles events and how vb handles events. There is no reason I can see that you would need a loop at all and it looks like you are trying to treat your subroutine as if it was main in c/c++. In c/c++ execution starts at main and events are handled one of 2 ways: either there is an infinate loop that is interrupted with an interrupt or you use some library function that stops execution. For instance scanf will stop and wait for you to make an input.
VB doesn't work that way. Nothing that I am aware of waits for inputs and there is no main. It looks like you are expecting your inputbox to work like a scanf. What will happen in vb is that the program will immediately read your inputbox then go immediately to the next line of code regardless. Everytime you do something vb looks for a subroutine that matches the event and if it finds one it call that sub and goes till it finishes execution. In general I think you are making your code way more complicated than it needs to be.
Lets get specific, you are getting an infinate loop it looks like because it looks like the assignment of random to input probably never executes because it is nested in a case that never executes. Therefore your loop always test something other than random. But to be honest I don't think you need a loop at all.
I might be misunderstanding your project cause I don't understand the logic of some of your code. But if I am understanding it correctly I would do it like below.
dim inputnum as integer, randomnum as integer<br />
<br />
'create a random number<br />
inputnum = textbox1.text<br />
if inputnum > randomnum then<br />
'move picture up<br />
elseif inputnum < randomnum then<br />
'move picture down<br />
else 'they're equal<br />
'game is done<br />
end if
ps if you have option strict on you may need to do some casting on this statement inputnum = textbox1.text but I'm not sure.
|
|
|
|
|
Mike, Thanks for the help. I thought I may have been over complicating things. I will try it out and see what happens. Thanks again.
DK
|
|
|
|
|
Mike, Thanks for getting me to simplify things. I have a solution that meets the criteria. Unfortunatly it does not use the principals outlined in the chapter I am working on (Decisions and Loops). I have posted my solution below:
Option Strict On
Option Explicit On
Public Class mainForm
' declare variable for form
Dim random As Integer
Private Sub mainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'declare variable
Dim randomGenerator As New Random
'generate random number and direct focus to text box
random = randomGenerator.Next(1, 11)
inputTextBox.Text = "0"
inputTextBox.Focus()
End Sub
Private Sub startButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startButton.Click
' decalre variables
Dim randomGenerator As New Random
Dim input As Integer
Dim isConverted As Boolean
'convert input and validate input
isConverted = Integer.TryParse(inputTextBox.Text, input)
If isConverted = True Then
'direct focus to text box
inputTextBox.Clear()
inputTextBox.Text = "0"
inputTextBox.Focus()
' Decision Tree
If input > random Then
pointPictureBox.SetBounds(82, 162, 100, 50)
displayLabel.Text = "Last Guess was " & input
input = 0
inputTextBox.Focus()
ElseIf input < random Then
pointPictureBox.SetBounds(82, 82, 100, 50)
displayLabel.Text = "Last Guess was " & input
input = 0
inputTextBox.Focus()
Else
pointPictureBox.SetBounds(82, 122, 100, 50)
displayLabel.Text = random & " is correct"
End If
Else
' if invalid iput then show
MessageBox.Show("Input Number from 1 to 10")
End If
End Sub
Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click
'Show Random and Close Application
MessageBox.Show("The number was " & random, "Answer", MessageBoxButtons.OK)
Me.Close()
End Sub
Private Sub newButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles newButton.Click
' Generate random number and direct focus to text box
Dim randomGenerator As New Random
random = randomGenerator.Next(1, 11)
inputTextBox.Focus()
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
End Class
|
|
|
|
|
Well I'm glad I was able to at least partially help you. I'm not sure what to tell you now though since I probably don't have your book I can't really help you to make it conform with the book.
good luck
Mike
|
|
|
|
|
Hi,
As the title says?
How?
I tried with
button.image = image.fromfile(image.ico)
...
doesn't work
thanks
|
|
|
|
|
try
add the icon files to the application resources then
button.image = my.resource.iconfilename
help everyone
Falling down is not defeat...defeat is when u refuse to get up...
|
|
|
|
|
unix_master01 wrote: doesn't work
What is not working? You have to describe better than that. No image? Exception? What?
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi,
you can take Imagebutton and give imageURL = "your ico file"
simple
Thanks,
Sun Rays
To get something you must have to try once.
My Articles
|
|
|
|
|
hi all i am working on a project that will store and display and print yellow pages.
please suggest me what control should i use to get it done.
i am not interested in crystal report.
my requirement is to display the print the whole data in database in less time as possible.
some body has any idea.
help everyone
Falling down is not defeat...defeat is when u refuse to get up...
|
|
|
|
|
Use the PrintPreviewdialog if you want to print something not allready on the screen, otherwise use the printform control, you can download it from microsoft. It's in the vb.net powerpack.
|
|
|
|
|
i need the code for login to windows using VB.NET2003????
for example, when your computer is standby and you want to login again while program is running
|
|
|
|
|
1. Do not cross post.
2. Give your message titles some meaning. We don't care if it's urgent or you need help.
3. We are not just going to hand over code to you. Either search for it, or write it yourself.
|
|
|
|
|
leckey wrote: Current Rant: "Sally Field Must Die!"
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Thanks for pointing that out--I need to update it!
|
|
|
|
|
Hi,
I have made a custom control, the control has only 1 textBox and one button.
But i can't show the control in normal way .show() . I need to show the control in a panel so i'm using this code:
If treeView1.Nodes.Item("nodeTarife").IsSelected Then
Dim k As New conTarife ' this is the custom control
SplitContainer1.Panel1.Controls.Add(k)
k.Show()
End If
What am I doing wrong?
Thanks!
|
|
|
|
|
From the code you've posted, you haven't done anything wrong. You really should even need the Show line. The only thing I can think of, without blaming anything on the control itself, is that Panel1 of the SplitContainer is hidden on the left side of the Split.
|
|
|
|
|
Cannot open View Designer in Visual Studio.And My View Designer show this
Message!!!!!
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Hide
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)
|
|
|
|
|
Does this happen on any other machine you might have around? Sounds like potential for bad memory.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Please, Help me if anybody can!!!!!
I want to generate own Report from my project,not from Crystal report Software.
I used following control in VB6 to generate Crystal.
CRViewer.This control can get Crystal Report Viewer component.
Like this VB6 code,i am using this control in VB.Net,
Friend WithEvents crvReport As CRVIEWERLib.CRViewer
Me.crvReport = New CRVIEWERLib.CRViewer
And my form has Preview command button to preview own report from this form.If user click this Preview button ,user can preview his own report.For
this ,i am using this code in cmdPreview_Click().
Call frmpReport.ShowReport(m_astrType, m_strColumn, m_aintWidth, m_astrFSource, blnSave)
,but my project face with problem in this line.
Call frmpReport.ShowReport(m_astrType, m_strColumn, m_aintWidth, m_astrFSource, blnSave)
Error Message is
Unable to cast COM object of type 'CRVIEWERLib.CRViewerClass' to interface type
I will waiting for your answer.THANKS For ur Answer.
|
|
|
|
|
You posted this same thing the day before. Obviously, no one has a solution for you.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
I am using ASP.NET to create this datagrid, but I am trying to do all of the code in the VB code section and not the html section.
I am building a datagrid as follows:
3 Text Columns
1 Link Button Column
1 Push Button Column
In Property Builder, I have set the "Command Name" for both the Link Button and Push Button columns to "Select". This is so that when the user clicks on the column, I can use the SelectedIndexChange event and determine what row they are clicking on. The only problem is that in doing so, I cannot determine the column they are clicking on. Is there any code I can use on the VB side in the datagrid SelectedIndexChange sub to determine what column was clicked in? Anything from the header of the column or even just the column index itself. The SelectedIndexChange sub is written such:
Private Sub dg_LastSevenDays_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
dg_LastSevenDays.SelectedIndexChanged
End Sub
When I try to see what data I can get from 'sender' or 'e', all they reference is the datagrid itself and not anything within it.
Search for solutions online, I found a few that would work if this was a compiled application and not a web application. Has anyone run into this before?
David
|
|
|
|
|
How can I change my language keyboard into Arabic only
Ahmed hassan
|
|
|
|
|
In a program or in windows?
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
In a program in textbox
Ahmed hassan
|
|
|
|