|
I have a button that when clicked the total of set of figures in a listbox is displayed in a textbox. How can I disable that button so that if there is nothing in the listbox and it is clicked, my program does not crash, and it is enabled again when there are contents in the listbox.
|
|
|
|
|
listbox.Items.Count will give you the number of items in the listbox.
button.Enabled enables/disables the button.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
index = listbox1.SelectedIndex
listbox1.Items.RemoveAt(index)
The above code is used to remove an item from the listbox. I have tried listbox1.items.count but program still crashed when button was clicked and there were no items in the listbox
|
|
|
|
|
It's pretty obvious that this code isn't going to work if there are no items in the listbox.
listbox1.SelectedIndex will be -1 if there are no items in the list. Don't execute the second line of code if this is the case.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Is there a line of code I can use then if
index = listbox1.SelectedIndex
listbox1.Items.RemoveAt(index)
is used, so that the program does not crash when index =-1
I tried using an if statement:
if listbox1.selectedindex =-1 then
msgbox(" "),
but it still crashed.
|
|
|
|
|
You should check the details of the error and amend your code accordingly.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
I want to connect to access database, and check if the entered pin numbers and the ones in the database match or not.
Public Function mdbValidatePin(ByVal mailbox As String, ByRef retcode As String) As DB_RETURN_CODE
'open database and check/validate the PIN.
mdbValidatePin = DB_RETURN_CODE.MDB_SUCCESS
End Function
But I am not sure how to open and check/validate the pin from the database. Can anyone help me with it?
Thanks
|
|
|
|
|
You need to learn how to use ADO.NET.
If you search the web you will find plenty of examples of how to execute an MS Access query from .NET.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
I am writing a business systems program for an industry. I want it to be both XP and Vista compatible. Are there certain things that I need to do when writing the program and/or the set up program, to be compatible with XP and Vista?
Is there a list of compatibility issues somewhere?
I have Visual Studio 2003 and SQL Server Express.
|
|
|
|
|
My first suggestion to you would be "NOT" to use Visual Studio 2003 / .NET 1.1 for an application you want to run on Vista. Although it is possible to run .NET 1.1 on Vista based on my personal experience I have found it to be extremely buggy.
Use Visual Studio 2005 or Visual Studio 2008 Express instead ( free for download here http://msdn2.microsoft.com/en-us/express/default.aspx[^] ) and target the .NET 2.0 framework instead (a lot more stable then 1.1 or 3.0 at this point).
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
|
|
I'm working on a project that stores data in a text file. I want to take the data from the file and load it into a listbox that is contained within my form. However no matter what I try to code into the form's load event I cannot seem to get the data to show up. Also the form is designed to allow users to add new entries into the listbox. I'm using textboxes for the input and when you click an add button the data is added to the listbox however it is displayed vertically instead of horizontally. Anyone know how to fix it?
|
|
|
|
|
Hello,
You have not mentioned the format of the data in the text file. Is the data in the form of
tab/comma separated values or simple text lines. If you wish to display all the lines in a text
box as separate items in the Listbox, then you can use the given code. This uses the Stream Reader
object to read the lines into the Listbox. You have to import the file System.IO.
Dim stream As New StreamReader(<filename path="">)
Dim str As String
While Not stream.EndOfStream
str = stream.ReadLine
ListBox1.Items.Add(str)
End While
I am unable to understand your second requirement. Can you explain it more.
Regards,
Allen Smith
Software Engineer
ComponentOne LLC
www.componentone.com
|
|
|
|
|
Thanks Allen for the help. The 2nd requirement is that currently when I click add the data appears in the listbox like this:
1223
Joe Smith
Manager
Some Address
SSN
I want it to input like this:
1223 Joe Smith Manager Some Address SSN
|
|
|
|
|
Hello,
In this case, what you can do is concat each of the textbox values in a string object and then
add them in the Listbox. For example, you input all the above values separately from TextBox1 to
Textbox5. Now on button click, you can use the following code.
Dim str As String = ""
str = str & " " & TextBox1.Text & " " & TextBox2.Text & " " & TextBox3.Text & " " & TextBox4.Text & " " & TextBox5.Text
ListBox1.Items.Add(str)
I believe this should resolve your issue.
Regards,
Allen Smith
Software Engineer
ComponentOne LLC
www.componentone.com
|
|
|
|
|
Thanks Allen for the help. Now that sent that to me it seems so easy that I should ahve gotten it.
|
|
|
|
|
hi,i have made an application in C# and vb.net,it working fine in C#, now when converting for C# to vb.net there is situation in which i have to call thread with 2 parameters, in C# i have used anyomous method here is code of that
ThreadStart st = delegate { ParseURL(strURL, this); };<br />
Thread th = new Thread(new ThreadStart(st));<br />
th.Start();
i am trying to convert that code in vb.net but it did not work
dim st as ThreadStart = delegate( ParseURL(strURL, Me))
Dim th As New Thread(New ThreadStart(AddressOf ParseURL))
th.start()
then i used but i accept only one parameter not 2 parameters.
<br />
Dim th As New Thread(New ParameterizedThreadStart(AddressOf ParseURL))<br />
th.IsBackground = True<br />
th.Start(strURL)<br />
plz tell me how to pass 2 parameters to thread in vb.net
Regards.
Tasleem Arif
|
|
|
|
|
The C# code actually doesn't send any argument at all when starting the thread. The values are put in the delegate object instead.
As anonymous methods are not available in VB.NET, you can't use this trick, so you have to use a different one.
Create a class that has two member variables and a method (or add them to an existing class). Create an instance of the class and put the values in the variables and use the method to start the thread. That way the method has access to the values.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
In VB6 i used to start my project from a Sub Main() which resided in a module.
This codei n sub main then initialised many things and called various forms, ie splash screen and so on.
However i cannot get the VB.NET windows application to start in this way. The property settings require that the start up be a form, unless i use a different app type (ie console app or other).
I'm new to VB.NET so would appreciate any best practice advise on this matter and how other developers are currently handling this.
Many Thanks
|
|
|
|
|
Every Class has a constructor and If you don't create one .NET will create one for you. As form is also a Class so it has its own Constructor it calls whenever we create an object of it so the best place to initialize things is the Constructor and in VB.NET its name is 'New' you can find the Constructor of your form inside 'Windows Form Generated Code'.
For Example:
Sub New
'Initialize Code here
End Sub
Hope it helps !
AliAmjad(MCP)
First make it Run THEN make it Run Fast!
|
|
|
|
|
I'm having difficulty finding the windows generated code. I can see the code from the forms designer but that does not contain the constructor.
|
|
|
|
|
When you click on the '+' sign besides "Windows Form Designer generated code" means when you expand it you'll see the code e.g.
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
'Your code goes here....
End Sub
I think you should buy a book because It'll really help you to clear your concepts !
hope it helps !
AliAmjad(MCP)
First make it Run THEN make it Run Fast!
|
|
|
|
|
AliAmjad
Thanks, i do have a book and have seen the code you mention before. But for some reason it is not in my current form.
When i select 'show all files' im the solution explorer, a plus sign appears next to my form which, if expanded, show me a Form.Designer.vb file and a Form.resx file.
I can see some code with 'Mybase.Disposing' in the Form.Designer.vb file but cannot find the form constructor anywhere.
I can create a constructor, with the same code as your comment and the IDE doesn't complain, but i would like to know why it is'nt there in the first place.
I have also tried adding in another form, just in case the code was accidentily deleted but this was the same.
|
|
|
|
|
first create a Start up module I alway call it mMain and than create the Main() sub.
than from the project menu select properties then from the application tab select the
startup object as sub Main()
in sub Main you should put the following code at the end:
Application.EnableVisualStyles()
Application.DoEvents()
Application.Run(MainFrm)
|
|
|
|
|
When i uncheck the 'Enable application framework' though what implication does this have?
|
|
|
|