|
How do I write code for?
Catch Format Exception (invalid input)
This is for a program that only has you selecting from 0-3 and anything else is an invalid input.
|
|
|
|
|
You only want the user to be able to enter 0, 1, 2, or 3 in a text box?
|
|
|
|
|
That is correct or they get a format exception error.
|
|
|
|
|
In the textbox's KeyPress event, check to make sure that the character entered is either a 0, 1, 2, or a 3. If it is, then set e.Handled = True . If not, then you can raise the error that you want to raise and set e.Handled = False .
|
|
|
|
|
Thanks, but I have to use a try catch statement for this one.
|
|
|
|
|
Hello everybody,
having to work with an uncommon image format (dpx, a bitmap which is not supported by GDI+) I tried a few libraries which support the format as well as Visual basic. My knowledge of VB is still too little to implement the new image object successfully and show a dpx-picture in a picture box.
Maybe somebody can help me with the basics a bit? In the particular case, I'm using a free graphics Library used by the famous XnView. My following code throws an error saying that the COM-Object couldn't be converted:
Imports GflAx
Private MyImage As GflAx.GflAx
Public Class clsXn
Public Sub ShowMyImage(ByVal fileToDisplay As String, ByVal xSize As Integer, _
ByVal ySize As Integer)
' Sets up an image object to be displayed.
If (MyImage IsNot Nothing) Then
MyImage.Dispose()
End If
' Stretches the image to fit the pictureBox.
frmHead.pbox.SizeMode = PictureBoxSizeMode.StretchImage
MyImage = New GflAx.GflAx
MyImage.LoadBitmap(fileToDisplay)
frmHead.pbox.ClientSize = New Size(xSize, ySize)
frmHead.pbox.Image = MyImage '<------- ERROR THROWN
End Sub
end class
The function is called from the form with
Private Sub btnTestXn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTestXn.Click
Dim Xn As New clsXn()
Xn.ShowMyImage("D:\Test\pic1041.dpx", 192, 108)
End Sub
What did I forget or how can I solve the issue?
I'm a bit afraid that I ran into a GDI+ issue that only accepts certain formats, but I thought using the third party object this would have been solved.
Thanks for any advice,
Michael
|
|
|
|
|
Your code is trying to convert an object of type GflAx to a .NET Image object. That's not going to work. The GflAx object has to expose some method to return an Image object. You're best source of information on this would be the people or forums that created/deal with this image library.
|
|
|
|
|
Thank you, Dave.
I've tried the only two methods from the help file which seemed to make sense (object.LoadBitmap and object.GetPicture), with similar result. As you suggest I'll get in touch with the developers.
|
|
|
|
|
Yeah, both of those methods tell the object to load a file into itself. There has to be a different method or property of that object that returns the image itself, in a format that can be used by the Image class.
|
|
|
|
|
In my windows form there are few comboBox.They are bind with database. But when I run the form and select any comboBox and backspace or press delete button then comboBox delete.But I don't like so. How to avoid this.I like to behave comboBox like webpage. Such as when I click in any comboBox item name(not in black triangle-arrow), comboBox should open the item list.
|
|
|
|
|
Saam_cse wrote: But when I run the form and select any comboBox and backspace or press delete button then comboBox delete.
If the combobox is being removed from the form, you're still in the designer, not the running application. You cannot just click on a control and delete it unless you provide the code to do so.
|
|
|
|
|
ok see this, the items on the Combobox will not be edited.
comboBox1.Items.Add("First");
comboBox1.Items.Add("Second");
comboBox1.Items.Add("Third");
comboBox1.Items.Add("Forth");
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
Hope this is what you want
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Set its DropDownStyle property to DropDownList.
|
|
|
|
|
Hi friends,
I have an interesting problem in vb.net. And I am struggling to get a solution for this..m trying for the past 3days.. It’s to calculate moving average for the inputs given by the user..
The following are the steps..
1, get 2user inputs in textbox(1st input is number is periods, 2nd is moving range)
2, after getting both the user inputs, the user will click on an input button which must dynamically generate rows for the number of periods given by the user as well as a calculate button must appear dynamically.
3, the user again inputs the values for all the dynamically generated rows and when by pressing calculate button, the moving average for the given moving range must appear in another column
Im half way through and I have attached my progress here.. I would greatly appreciate if u complete it for me.. thanks in advance
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim TxtDyn1 As TextBox()
Dim TxtDyn2 As TextBox()
Dim TxtDyn3 As TextBox()
Dim TxtDyn4 As TextBox()
Dim numofper As Integer
Try
'to check the textbox for empty
If Not TextBox1.Text Is String.Empty Then
numofper = TextBox1.Text
ReDim TxtDyn1(numofper)
ReDim TxtDyn2(numofper)
ReDim TxtDyn3(numofper)
ReDim TxtDyn4(numofper)
Else
Exit Sub
End If
'To create the dynamic text box and add the controls to panel
For i As Integer = 0 To numofper - 1
TxtDyn1(i) = New TextBox
Panel1.Controls.Add(TxtDyn1(i))
Next
For j As Integer = 0 To numofper - 1
TxtDyn2(j) = New TextBox
Panel2.Controls.Add(TxtDyn2(j))
Next
For k As Integer = 0 To numofper - 1
TxtDyn3(k) = New TextBox
Panel3.Controls.Add(TxtDyn3(k))
Next
For l As Integer = 0 To numofper - 1
TxtDyn4(l) = New TextBox
Panel4.Controls.Add(TxtDyn4(l))
Next
Dim mybutton As New Button (THIS S NOT WORKING )
mybutton.Text = "button 2"
AddHandler mybutton.Click, AddressOf button2.click
Me.Controls.Add(mybutton)
Catch ex As Exception
MsgBox("Enter a valid Number")
End Try
End Sub
End Class
|
|
|
|
|
You've done nothing but create arrays of controls. There is no code to generate any moving average or anything else. You're missing the meat of the application. Forget about the User Interface stuff for now and create the code to generate the data you need. This is going to need some kind of input to do and this need to going to dictate how you do the UI. You may even end up scraping everything you have so far to do this.
|
|
|
|
|
hi .. i am new to vb.net and i have a problem in maintaining values in two button events.. so pls help me.. i have just added some code to that.. please correct them and help me completing.. im struggling without enough source to refer..
Partial Public Class _Default
Inherits System.Web.UI.Page
Dim textdynamic1 As New ArrayList()
Dim textdynamic2 As New ArrayList()
Dim textdynamic3 As New ArrayList()
Dim textdynamic4 As New ArrayList()
Dim TxtDyn1 As TextBox()
Dim TxtDyn2 As TextBox()
Dim TxtDyn3 As TextBox()
Dim TxtDyn4 As TextBox()
Dim k As Integer
Dim a As Integer
Dim b As Integer
Dim l As Integer
Dim numofper As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
'to check the textbox for empty
If Not TextBox1.Text Is String.Empty Then
numofper = TextBox1.Text
ReDim TxtDyn1(numofper)
ReDim TxtDyn2(numofper)
ReDim TxtDyn3(numofper)
ReDim TxtDyn4(numofper)
Else
Exit Sub
End If
'To create the dynamic text box and add the controls to panel
For i As Integer = 0 To numofper - 1
TxtDyn1(i) = New TextBox
Panel1.Controls.Add(TxtDyn1(i))
textdynamic1.Add(textdynamic1)
Next
For j As Integer = 0 To numofper - 1
TxtDyn2(j) = New TextBox
Panel2.Controls.Add(TxtDyn2(j))
textdynamic2.Add(textdynamic2)
Next
For k As Integer = 0 To numofper - 1
TxtDyn3(k) = New TextBox
Panel3.Controls.Add(TxtDyn3(k))
textdynamic3.Add(textdynamic3)
Next
For l As Integer = 0 To numofper - 1
TxtDyn4(l) = New TextBox
Panel4.Controls.Add(TxtDyn4(l))
textdynamic4.Add(textdynamic4)
TxtDyn4(l).Enabled = False
Next
Catch ex As Exception
MsgBox("Enter a valid Number")
End Try
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
Dim nval As Integer
nval = TextBox2.Text
For Each b As Integer In textdynamic4
Do
For Each a As Integer In textdynamic3
a += TxtDyn3(k).Text
Next
Loop While k <= nval
TxtDyn4(l).Text = a / nval
Next
End Sub
End Class
|
|
|
|
|
Please help me to disable / hide Start Orb in Windows Vista using Visual Basic 6 (not VB.Net, VB2005 or VB2008 or C# or C++ !!!).
Such solution on this website was proposed by Simon B. using VB2008, however I need it for Visual Basic 6.
Thanks in advance for your help.
|
|
|
|
|
Hiding the Taskbar and Startmenu (start orb) in Windows Vista[^]
Now before you complain that that code is C#, the APIs are all the same. All you have to do is use the API viewer to convert it to VB6. Should be a piece of cake to do. I don't know if that's the article you referenced or not, because that one is not VB.
Someone on here[^], suggested the following line: ShowWindow(FindWindowEx(NULL, NULL, MAKEINTATOM(0xC017), NULL), SW_HIDE); Again, you can easily do that in VB because it's just two basic API calls.
|
|
|
|
|
Hello,
Does anyone know how to use a Function Delegate? I have used many Sub Delegates but the function escapes me....
Here's my Code...why does this not work?
Public Delegate Function FormsUIThread(ByVal oFrm As Form) As Form
Public Shared Function GetOnFormsUIThread(ByVal oFrm As Form) As Form
If oFrm Is Nothing Then Return Nothing
If oFrm.InvokeRequired Then Return oFrm.Invoke(New FormsUIThread(AddressOf GetOnFormsUIThread), oFrm)
Return oFrm
End Function
Thanks
Nathan
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
What do you mean by "it doesn't work"? Does it compile? throw an exception? Return an unexpected result? ...
|
|
|
|
|
Sorry for leaving that out...it says I'm still in violation of cross-threading. The invoke should of got me on the forms thread but it is not working.
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
nlarson11 wrote: The invoke should of got me on the forms thread
The Invoke does execute in the UI thread, but that is totally pointless as all you are doing is returning a reference to the form. The reference doesn't get any different from being returned from another thread, and when you use the reference, you are still using it from your thread.
It's whatever you do with the form that you need to call using Invoke.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi Nathan,
Following is a demo of Funtion Delegates in VB.Net
BEGIN CODE
Imports System
Public Class MainClass
Dim emp As New Employee("First Name", "Last Name")
Private Delegate Function NumEmployeesDelegate() As Integer
Shared Sub Main(ByVal args As String())
Dim show_num As NumEmployeesDelegate
show_num = AddressOf Employee.GetNumEmployees
Console.WriteLine(show_num().ToString)
End Sub
End Class
Public Class Employee
Private m_FirstName As String
Private m_LastName As String
Private Shared m_NumEmployees As Integer = 0
Public Shared Function GetNumEmployees() As Integer
Return m_NumEmployees
End Function
Public Sub New(ByVal first_name As String, ByVal last_name As String)
m_FirstName = first_name
m_LastName = last_name
m_NumEmployees += 1
End Sub
Public Overrides Function ToString() As String
Return m_FirstName & " " & m_LastName
End Function
Private disposedValue As Boolean = False ' To detect redundant calls
End Class
END CODE
Hope thhis helps
Regards,
John Adams
ComponentOne LLC
|
|
|
|
|
Hey John,
Thank you. I need an example that deals with a Forms UI thread where I have to test if an invoke is required and invoke to get on that form's thread. I know i can do this with a Sub Delegate but the Function Delegate I can't?
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
Is the error happening inside this function or after the function call when you use the value returned from it?
If it is the latter, than the problem is that the call to Invoke only makes GetOnFormsUIThread be on the main thread. The function that called it originally is still on a different thread and any access to the members of the form returned from the function will continue to throw an exception.
|
|
|
|