|
I am relatively new with programming and am having some issues with the following code. It is basically a calculator where I have 3 line of numbers in textboxes LINE1, LINE2 and LINE3. When I hit the + key on my keyboard it will add the first two numbers and displays the answer in the textbox LINE1. However it also shows “+” at the end of the result ie ”45+”. How do I show the result "45" without showing the key that has been pressed. Also happens when I use the other keys
as well. ( / * - )
Any help is appreciated
Thanks
Martin
Public Class HELP
Dim I As Integer = 1
Dim ANS, X, Y, Z As Double
Private Sub LINE1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles LINE1.KeyDown
If e.KeyCode = Keys.Add Then ' 3 values entered. 1 for each line and the plus key is pressed
If I = 1 Then
Z = CDbl(LINE3.Text)
End If
I = 2
X = CDbl(LINE1.Text)
Y = CDbl(LINE2.Text)
ANS = X + Y ' Addition of Line1 and Line2 as would a calculator
LINE1.Text = ANS
LINE1.SelectionStart = LINE1.Text.Length
LINE1.Select() ' Why is ther a plus sign at the end of the answer
LINE2.Text = LINE3.Text
LINE3.Text = ""
End If
End Sub
End Class
|
|
|
|
|
after you do your calculation put this on the next line:
e.handled = true 'this will handle the key, stopping its data being passed to the underlying control
so:
If e.KeyCode = Keys.Add Then ' 3 values entered. 1 for each line and the plus key is pressed<br />
If I = 1 Then<br />
Z = CDbl(LINE3.Text)<br />
End If<br />
I = 2<br />
X = CDbl(LINE1.Text)<br />
Y = CDbl(LINE2.Text)<br />
ANS = X + Y ' Addition of Line1 and Line2 as would a calculator<br />
LINE1.Text = ANS<br />
LINE1.SelectionStart = LINE1.Text.Length<br />
LINE1.Select() ' Why is ther a plus sign at the end of the answer<br />
LINE2.Text = LINE3.Text<br />
LINE3.Text = ""<br />
e.handled = true<br />
End If
|
|
|
|
|
Hi,
have a look at the KeyDown documentation...
from MSDN: Handled is implemented differently by different controls within Windows Forms.
For controls like TextBox which subclass native Win32 controls, it is interpreted to mean
that the key message should not be passed to the underlying native control. If you set
Handled to true on a TextBox, that control will not pass the key press events to the
underlying Win32 text box control, but it will still display the characters that the user typed.
If you want to prevent the current control from receiving a key press, use the SuppressKeyPress property
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
That was the answer thanks for your help
|
|
|
|
|
Hi Friends
Am in a bit of a pickle, and I now don't know how to fix this. I am trying to update the data in my dataset, and I am getting a concurrency violation. The application I am developing is to be used by, only one user, and there is no way that some one else could be using the dataset.
What could be the cause of this?
Thanks , I hope u will be able to help me.
|
|
|
|
|
Concurrency isn't just a multiuser issue. There are more than a couple of ways your own code can think it's updating records that it's not. The most common of which happens when your code goes to update a single record (such as when using the DataAdapter or TableAdapter), the number of affected records comes back 0 or greater than 1, because your table's primary key isn't setup properly, or if it doesn't even have one.
|
|
|
|
|
Hi, I got a problem when I try to get the value of numeric up down control. I have developed an application in vb2005 and contain a build in control numeric up down control. On the form i set the value of this control to 5 and in the code if i use the below code:
msgbox(numericupdown1.value)
the result in message box is 5. It is correct. But when I try the below code:
dim i as integer<br />
for i = 1 to numericupdown1.value<br />
listbox1.item.add(i)<br />
next
There is no value add into the listbox. I won't what is the problem? when I try to run the code in debugging mode, I found that numericupdown1.value=5D not equal to 5. So when the code reach the for next statement, it ignore and nothing happend. Does anyone know how could i solve this problem? Thank in advance.
|
|
|
|
|
did you check the type of NUD.Value?
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Luc Pattyn wrote: did you check the type of NUD.Value?
How?
|
|
|
|
|
by reading the documentation!
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
The Value property on a NumericUpdown control is a decimal (that's what the "D" indicates). Try casting it to an integer value before you use it in the for loop.
dim i as integer
dim max as integer
max = Convert.ToInt32(numericupdown1.value)
for i = 1 to max
listbox1.item.add(i)
next
|
|
|
|
|
Thank you very much for your help. I will try this code.
|
|
|
|
|
Kanel, this one was so easy to solve, it's silly. All you had to do was click on the Value part of the code you posted and hit <F1>. It's spelled out right in the docs what the return type is.
Even easier, you didn't even have to do that. After you typed numericupdown1 and hit the period key and started to type Value , Intellisense would have popped up and shown you right there what the return type is.
Public Proprty Value() As Decimal
Gets or sets the value assigned to the spin box (also known as an up-down control).
I know we keep beating this into everyone's head around here, read the documentation!! We do it for a reason. Rule number 1 in troublshooting: Verify, verify, verify. Verify that your using the correct types. Verify that the values you are putting in and using are what the object/method expects. Verify that you know, not assume, how the object works! The only way to do that is to read any and all documentation on the object.
|
|
|
|
|
What does the code below do??
Err.Clear
Set ts = fso.OpenTextFile("C:\userlevel\userlevel_billing.txt", 1, False, -2)
If Err.number = 0 Then user_level = user_level + 1
|
|
|
|
|
This belongs in the web dev forum, really. Why on earth would anyone be an asp beginner ? asp sucks.
The fso is the file system object created via COM. It can be called anything, but it's often called that.
Without even remembering the details, it's obvious to me that this code reads the text from a text file into a variable, and if no error occurs, the variable user_level is incremented. Google is the best place to find out what those options in the function call mean, but their lack of readability is one example of why asp is hideous.
Most people create const variables to contain the flags that things like 1 and -2 represent, in a vain attempt to make ASP code readable.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi
I programming a personal project, i would like about than how read a mp3 file from vb, but not only the header as i found many examples, else i would like read a mp3 file totaly to after i make others operations with him.
Thanks for help about how can know the mp3 structure, read the headers and load mp3 music section, greetings from mexico.
|
|
|
|
|
Hi. I am working on a form designer program in vb.net. The user will able to add, remove, and manipulate controls on a form.
I saw an article once about saving a form as a file (I believe it was XML), but I can't seem to find it. Can anyone help me find out how to save and load a form from a file?
Thanks,
Richard Faulkner
|
|
|
|
|
Have you done an article search here ( assuming you are meaning you saw the article here )?
"Find it your bloody self - immediately!" - Dave Kreskowiak
|
|
|
|
|
I am not sure if the article was from this site, but I have done a search and came up with no results
|
|
|
|
|
Hi,
as the title says?
But do it programmaticly, not within the designer (drag & drop)
I have created a XML file with another function, it is valid.
How to extract the XMl file and show its columns and data in a datagrid?
I have tried using a dataset, I have filled the dataset with the xml data. But I don't know how to show it in a dataGrid View.
Thank you very much in advance!
|
|
|
|
|
unix_master01 wrote: I have tried using a dataset, I have filled the dataset with the xml data. But I don't know how to show it in a dataGrid View.
MyDataSet.ReadXml(filepath)
DataGridView1.DataSource = MyDataSet
DataGridView1.DataMember = "someTableNameInDataSet"
|
|
|
|
|
Hi Friends,
Using VB.net 2003 and sqlserver 2000
Private Sub checkclick()
If CheckBox1.Checked = True Then
month1 = "January"
End If
If CheckBox2.Checked = True Then
month2 = "February"
End If
If CheckBox3.Checked = True Then
month3 = "March"
End If
If CheckBox4.Checked = True Then
month4 = "April"
End If
If CheckBox5.Checked = True Then
month5 = "May"
End If
If CheckBox6.Checked = True Then
month6 = "June"
End If
If CheckBox7.Checked = True Then
month7 = "July"
End If
If CheckBox8.Checked = True Then
month8 = "August"
End If
If CheckBox9.Checked = True Then
month9 = "September"
End If
If CheckBox10.Checked = True Then
month10 = "October"
End If
If CheckBox11.Checked = True Then
month11 = "November"
End If
If CheckBox12.Checked = True Then
month12 = "December"
End If
End Sub
Dim con As SqlConnection = New SqlConnection("workstation id='YOUR-A77D0E1DAD';packet size=4096;integrated security=SSPI;data source='.';persist security info=False;initial catalog=FORUT")
Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
checkclick()
Try
Dim DA As SqlDataAdapter = New SqlDataAdapter '("SELECT * FROM FINACIAL_REQUEST_REPORT", CON)
Dim DS As New DataSet
DA.SelectCommand = New SqlCommand
DA.SelectCommand.Connection = con
DA.SelectCommand.CommandType = CommandType.Text
con.Open()
If CheckBox13.Checked = True Then
DA.SelectCommand.CommandText = "SELECT * FROM FINACIAL_REQUEST_REPORT where YEAR1='" & NumericUpDown1.Text.Trim & "'"
Else
DA.SelectCommand.CommandText = "SELECT * FROM FINACIAL_REQUEST_REPORT where YEAR1='" & NumericUpDown1.Text.Trim & "' AND (MONTH1='" & month1 & "' or MONTH1='" & month2 & "' or MONTH1='" & month3 & "' or MONTH1='" & month4 & "' or MONTH1='" & month5 & "' or MONTH1='" & month6 & "' or MONTH1='" & month7 & "' or MONTH1='" & month8 & "' or MONTH1='" & month9 & "' or MONTH1='" & month10 & "' or MONTH1='" & month11 & "' or MONTH1='" & month12 & "')"
End If
DA.Fill(DS, "FINACIAL_REQUEST_REPORT")
con.Close()
Dim OB As New C_FINANCIAL_REQUISITION
OB.SetDataSource(DS.Tables("FINACIAL_REQUEST_REPORT"))
CrystalReportViewer1.Visible = True
CrystalReportViewer1.ReportSource = OB
Catch ex As Exception
MsgBox(ex.Message)
con.Close()
End Try
End Sub
Thanks a lot
|
|
|
|
|
Wow, there's a lof of stuff bad with this. OK.
Without doing anything to your database, which itself needs a redesign, you can build an SQL SELECT with and IN clause.
First, you don't need all the month* variables. Get rid of them.
Next, add a Tag value to each of your CheckBox's with the month name corresponding to each one. CheckBox1.Tag="'January'", CheckBox2.Tag="'Febuary'", ... (NOTE: The single quotes in those strings!)
Wire up all the CheckBox's CheckChanged events to the same handler. See the Handles clause at the end?? Add all of the CheckBox's to it.
Private Sub CheckBox_CheckChanged(blah, blah) Handles, CheckBox1.CheckChanged, CheckBox2.CheckChanged, ...
In this handler, cast the sender back to a CheckBox and get the Tag property from it. In an ArrayList collection, check to see if the Tag value is in the collection, if not, Remove it, else, Add it. A quick'n'dirty version of this would look something like:
Dim cb As CheckBox = DirectCast(sender, CheckBox)
If Not myMonthList.Contains(cb.Tag) Then
myMonthList.Add(cb.Tag)
Else
myMonthList.Remove(cb.Tag)
End If
Mind you, this code doesn't care if the checkbox is checked or not!! You might want to factor that into this code.
When you go to build the SQL query string, you'turn the collection of months, myMonthList in the above example, into a String of values seperated by commas, like this:
Dim months As String = String.Join(",", myMonthList.ToArray(GetType(String)))
You then make that list part of you SQL statement:
Dim sql As String = String.Format("SELECT * FROM Finacial_Request_Report WHERE year1='{0}' AND month1 IN ({1})", NumericUpDown1.Text, months)
You'll get a statement that looks something like this:
SELECT * FROM Financial_Request_Report WHERE year1=1980 AND month1 IN ('January','Febuary')
But, this is quick'n'dirty. A good solution would require you to redesign your database and scrap all the code you put up in your original post.
|
|
|
|
|
hii
i am able to draw a rectangle of any size , Now i want to draw small size of rectangles in big rectangle , so that user can align the controls.
And i want the big rectangle as dotted line . ( For example in vb .net show grid options ) in that they showed as dots) , but i want to show in rectangles . For example , Like Graph sheet
DVSRIRAM
|
|
|
|
|
All you have to do is draw a line from the top of the rectangle to the bottom, every so often acrossed the rectangle. Then repeat the process drawing lines across the rectangle.
You already have the position and dimensions of the rectangle. The rest is easy. Don't even think of copy'n'pasting this into your code, cause it's not real code. You actually have to write it yourself.
'Draw your rectangle, then do something like this:
For x = 0 to rectangleWidth Step spacing
DrawLine( x+rectangleLeft, 0, x+rectangleLeft, rectangleHeight )
Next
For x = 0 to rectangleHeight Step spacing
DrawLine( 0, x+rectangleTop, rectangleWidth, x+rectangleHeight )
Next
|
|
|
|
|