|
Right after you populate the combo box, set the SelectedIndex property to -1. Then it will be -1 if the user hasn't changed it.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
If by chance you're using Windows Forms, the combobox has an event that fires only when the user makes a selection. It's independent of the SelectedIndexchanged event. Handle the event and get the SelectedIndex property from there.
ComboBox.SelectionChangeCommitted[^]
Sometimes the true reward for completing a task is not the money, but instead the satisfaction of a job well done. But it's usually the money.
|
|
|
|
|
Buen día;
necesitaría un poco de ayuda.
Tengo un formulario de nombre "frmProcess" el cual contiene un StatusStrip de nombre "StaComment"
Por otro lado tengo un módulo el cual contiene la siguiente rutina:
Public Sub InitialMenu(lfrmActive as Form)
.
.
.
End Sub
Mi pregunta es, como hago para invocar al StatusStrip usando el parámetro form
Esto que estoy haciendo es una migración de un VB6 donde lo mismo se hacía de la siguiente forma:
Public Sub InitialMenu(lfrmActive as Form)
lfrmActive.staComment.Panels("Action").text=""
End Sub
Saludos
Translation:
od morning;
I'd need a little help.
I have a name form "FrmProcess " which contains a StatusStrip of name "StaComment "
On the other hand I have a module which contains the following routine:
Public Sub InitialMenu (lfrmActive as Form)
.
.
.
End Sub
My question is, how do I invoke the StatusStrip using the form parameter
This I am doing is a migration of a VB6 where the same was done as follows:
Public Sub InitialMenu (lfrmActive as Form)
LfrmActive. staComment. Panels ( "Action "). Text = ""
End Sub
Best regards
|
|
|
|
|
Go to the form, click on your statusstrip, and add a statuslabel. Go to properties, set "Modifiers" to public. Next, open your Module and change the code;
Public Sub InitialMenu (lfrmActive as Form)
lfrmActive.toolStripStatusLabel1.Text = "bla"
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi ALl.
I populated combobox from DB.
And now when user select the value, how can i get the ID back.Because the selectedindex id diffirent from the original ID.
Thanks.
|
|
|
|
|
Depending on what type of application you're developing, the SelectedValue should give you either the selected database ID, or a DataRowView containing the values loaded from the database.
If it doesn't, then you've not set up the binding correctly.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I just use comboboxname.text. It will be a text file. If you want to get something from the DB, forget the index and just use a sql statement "SELECT * FROM db WHERE value = '" & comboboxname.text & "'"
|
|
|
|
|
Use Value instead. Getting the ID from a table with millions of records is much quicker by ID than it is by searching for a string.
|
|
|
|
|
|
iam using vb.net2010 and phpmyadmin server onine ..
when i connect vb.net with phpmyadmin every thing work correctly with out any problem or warning..
but when i leave App (at running ) with out any action or event the problem rise
and tell me ("Fatal error encountered during command execution") ,
Note: the connection is open.
please help me
|
|
|
|
|
You will need to provide considerably more details than that. No one here can guess what your application is doing.
|
|
|
|
|
iam using vb.net2010 and phpmyadmin server onine ..
when i connect vb.net with phpmyadmin and execute query like this code
'--------------------
If mycon.State = ConnectionState.Closed Then
mycon.Open()
End If
Dim testid As Integer = 0
mydataAdapter = New MySqlDataAdapter("select ID from COMPANY order by ID DESC LIMIT 1", mycon)
mydataset = New DataSet
mydataAdapter.Fill(mydataset, "COMPANY")
If Me.BindingContext(mydataset, "COMPANY").Count > 0 Then
testid = mydataset.Tables("COMPANY").Rows(0).Item("ID")
End If
'------------------------------------------
...every thing work correctly with out any problem or warning..
but when i leave App (at running ) with out any action or event the problem rise
and tell me ("Fatal error encountered during command execution") ,
Note: the connection is open.
please help me
|
|
|
|
|
Unfortunately I am not familiar with any languages with a "V" in name...
Function zGetFolder( sFolder )
On Error Resume Next
Set zGetFolder = oFso.GetFolder( sFolder )
If Err.Number <> 0 Then
Wscript.Echo "Error connecting to: " & sFolder & VBlf & "[" & Err.Number & "]" & Err.Description
Wscript.Quit Err.Number
End If
End Function
Questions:
The line I don't understand is: Set zGetFolder = oFso.GetFolder(sFolder)
Why would you "Set" a call to oFso.GetFolder with "zGetFolder" the name of the function you are currently in???
I am also not quite sure what "On Error Resume Next" accomplishes with this construct.
|
|
|
|
|
In VBScript, if a function returns an instance of a class or any object, you have to SET the variable to that instance.
Also, "On Error Resume Next" is error handling, which would be a try/catch block in C#. Resume Next just tells VB to continue executing code even if an error occurs. It also sets the values of the Err object if an error does occur.
Basically, all that code boils down to this in C#:
var zGetFolder = new DirectoryInfo(sFolder);
You can find the documentation on the DirectoryInfo class here[^].
|
|
|
|
|
Thanks for the explanation. What you said makes perfect sense.
I still don't understand why you would do this:
Set zGetFolder = oFso.GetFolder( sFolder )
When zGetFolder is the name of the function that line of code is in.
Does this zGetFolder only exist in the scope of the function?
|
|
|
|
|
I think you'll find that the function is designed to return the folder to the calling method. Therefore
Steve Messer wrote: Set zGetFolder = oFso.GetFolder( sFolder ) should return the folder (it will be a variable in the calling function).
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Steve Messer wrote: When zGetFolder is the name of the function that line of code is in. That is how a function returns data to its caller. The name of the function is an alias for the name of the variable to return. So setting the name in that way, the caller of the function will receive the value obtained by GetFolder .
|
|
|
|
|
The GetFolder-Method comes from oFso. This must be declared somewhere else and means the FileSystemObject (Example : Set FSO = CreateObject("Scripting.FileSystemObject") ).
If you come from VBScript you will find a lot of differences (not only with the Code-Syntax) to .Net (it is independant if you take VB.NET or C#.Net).
modified 26-Feb-18 4:38am.
|
|
|
|
|
zGetFolder is NOT the name of a function. It's just a variable holding a value or, in this case, and object returned by the call to the GetFolder() function. The GetFolder() function is a member of the FileSystemObject class instance that the variable oFso holds.
|
|
|
|
|
So basically:
1. 'On Error Resume Next' turns on user error handling as the default behavior is to exit on errors
2. If the call to oFso.GetFolder returns an error the function will Echo out the error code and
continue execution instead of the normal behavior of exiting
This would make since as this is part of an ETL process which is just copying backups to a shared drive. The process doesn't need to stop if the shared drive is unavailable for some reason.
Thanks everyone!
|
|
|
|
|
Steve Messer wrote: the function will Echo out the error code and continue execution instead of the normal behavior of exiting
Not quite. The Wscript.Quit Err.Number line following the Wscript.Echo ... line will cause the script to quit, with no possibility for error handling code further up the stack to handle the error.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I didn't notice Wscript.Quit, In my mind I just saw to lines with Echo.
That takes all the mysteries out.
Thanks again!!
|
|
|
|
|
Dave Kreskowiak wrote: Basically, all that code boils down to this in C#:
Almost.
The GetFolder Method[^] generates an error if the folder doesn't exist. The DirectoryInfo constructor doesn't.
You'd need to check the Exists property, and either display a message or throw an exception if it returns False .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yeah, I know. There are other issues with the OP's understanding that I just didn't directly address because of time.
|
|
|
|
|
Hi,
I think, it's because of visual basic sripting (which is equal to VB 6)
The "SET" is for instancing the fso object ofso (Filesystem object i guess)
The on error resume next is a poor "try catch" implementation.
|
|
|
|