|
Hello all,
I'm new to VB, and I'm using VB5 Express and it's a great program tool. I also have some video tutorials for it. But unfortunately I'm having a problem using the snippet below:
http://www.a1vbcode.com/snippet-187.asp
When I create a form, and then add a button, then add the event for the button, then pasting in the code, I'm getting the dreaded
Name 'Listbox1', is not declared.
I'm not sure what I'm doing wrong, but I've looked for the answer, and I'm still stumped. Below is what the complete code looks like.
Public Class Form1
'Place the following code in a command button's click event
Private Sub cmdGetFilename_Click()
Dim sFilename As String
Dim sPath As String
'search for files with vbp extension
sPath = "c:\yourpath\*.vbp"
'use Dir$ to get first matching filename
sFilename = Dir$(sPath)
'retrieve remaining files matching the search pattern
'Dir$ returns zero length string when no match
Do While sFilename > ""
ListBox1.AddItem(sFilename)
'call Dir$ without parameters to get next filename
sFilename = Dir$
Loop
End Sub
End Class
----------------------------------------------------------------------------------------
Any help will be greatly appreciated, and thank you for your valued time.
Jason
|
|
|
|
|
Maybe you've changed the List Box name on the UI designer (ListBox1 is the default name).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
jasontor wrote: and I'm using VB5 Express
It's not VB5 Express. It's VB.NET 2005 Express Edition. If you say VB5, everyone will think you're talking about the 10 year old VB5, which didn't have an Express Edition.
jasontor wrote: When I create a form, and then add a button, then add the event for the button, then pasting in the code, I'm getting the dreaded
Name 'Listbox1', is not declared.
It would appear that you need to add a ListBox control to your form. By default, it's name will be ListBox1.
|
|
|
|
|
In the below code snippet, I know it does retrieve value of those specified columns from the Deals table, but look at dataReader("name") , what syntax is this? dataReader is declared as type of interface IDataReader, how can we use it in a way like calling a function? At the first glance, I think it's an overloaded operator - function form "()", but after checking with some documentation, in VB.Net, this operator isn't on the allowed operators list to be overload. So would anyone tell me what syntax is dataReader("name") . Many thanks.
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Microsoft.Practices.EnterpriseLibrary.Data.Sql
...
Dim lubc As New LookupBaseCollection(GetType(SectypeCommon))
Dim sqlCommand As String = "SELECT * From Deals"
Dim dbCommandWrapper As DBCommandWrapper = Me.database.GetSqlStringCommandWrapper(sqlCommand)
dbCommandWrapper.CommandTimeout = Me.database.GetConnection().ConnectionTimeout
Dim dataReader As IDataReader = Me.database.ExecuteReader(dbCommandWrapper)
While (dataReader.Read())
Dim sc As New SectypeCommon(dataReader("transtype").ToString())
sc.Name = dataReader("name")
sc.TheKey = dataReader("thekey")
sc.ShortName = dataReader("code")
...
End While
modified on Wednesday, March 30, 2011 10:16 PM
|
|
|
|
|
dataReader("name") is the short version of dataReader.Item("name"). You can do this because the property 'Item' is the default property.
|
|
|
|
|
Thanks very much. I didn't know that before.
|
|
|
|
|
how do i get the focus to change from a textbox to a button so that i dont have to keep moving my mouse around?
whenever i finish typing my entry into the textbox,
i want my focus to move over to the execute button so that the button will take action when i press "enter"
a little help would be nice
|
|
|
|
|
ricebowl09 wrote: uhm hey ive got a question
And that sets your post apart from the others in this forum ? A meaningful subject can attract people who can help you.
ricebowl09 wrote: how do i get the focus to change from a textbox to a button so that i dont have to keep moving my mouse around?
You need to capture the fact that you've finished typing. You can do that one of several ways. The most obvious is to handle the focus lost event of the textbox and move the focus to the button. Actually, if the button is the default for the form, I think enter will press it for you.
The other ways I can think of, are bound to drive your users mad. You shouldn't just magically move the focus to a button. You could handle the tab keypress and make it move the focus ( that happens for most controls, but for hte textbox, I think it usually just enters a tab ( as you'd hope )
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,
suppose your textbox & button have name txtFocus and cmdExecute then use following code at keyprees event of txtfocus
Private Sub txtFocus_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtFocus.KeyPress<br />
If e.KeyChar = Chr(13) Then<br />
cmdExecute.Focus()<br />
End If<br />
End Sub
hope this helps
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
|
|
|
|
|
Rupesh Kumar Swami wrote: Chr(13)
It would be far better to use Keys.Enter and check the Keys variable.
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 )
|
|
|
|
|
yes sir,
this is also a way(i think it is better)
but sir there are a lot of way to doing this thing & what option we accept , its depend on our skills
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
|
|
|
|
|
I find it simplest to se the tab order of the objects on the form to the correct flow and to disable the tabstop property on objects that do not need focus.
Set the cancel and where appropriate the accept buttons for the form.
Let the form do the rest!
Don't forget to explicitly cole the form rather than relying on the dialogresult - there used to be an annotying flash on the form in 1.0
|
|
|
|
|
recently i moved my website from unix hosting to windows hosting that only supports IIS and not apache. in the site i have a folder called /registered_users which can contain basically any sort of file. now since the .htaccess script handler is not there everyone can go access the file. the username and passwords are about 500 and password obviously is encrypted. I have a sql table that has unencrypted user/pwd now how could i create sumthing similar to what was there earlier. there are like hundreds of html pages within that folder which are added/deleted automatically.
I simply want to give access to entire folder if they login successfuly.
please help
|
|
|
|
|
Sounds like a question totally unrelated to VB.NET, have you tried the web dev forum ?
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 )
|
|
|
|
|
Hello,
I have a datagridview and I have put a combobox column using the designer.
I have set the properties for the datapropertyName, datasource, display member, and view member.
I have used the binding source and have filled when the form loads. The contents are all displayed in the combo box. This part is working ok
I have used the below to fill the binding source.
'Fill the incidents<br />
Private Sub FillIncidents()<br />
Try<br />
Me.TA_Incident_dsComponent_Equipment.Fill(Me.DsAddComponetAndEquipment.Incident)<br />
<br />
Catch ex As Exception<br />
MsgBox(ex.Message)<br />
End Try<br />
End Sub
My problem is that combo box will be filled with all the incidents that are in the database table. But I want to have a "None" option if the user doesn't want to select any incident.
The incidentID is an identity seed and is incremented each time a new incident is added. So I just can't add a new false record with a "None" field.
I didn't notice any text property in the designer when I added the combobox column. I thought I could set the initial text property to display "None".
Is there any method to do this?
Many thanks for understanding my question and any suggestions.
Steve
|
|
|
|
|
Probably the best option is to add a new record with an id of "0" or any other number (but i like to use 0's) and a description of "None" to your datatable, for this, turn of the autoincrement and insert that reord, then turn autoincrement on again
To just display none when no incident is selected:
In the columns designer, select the comboboxcolumn and click in the DefaultCellStyle, in the new window that will open, set the NullValue property to "None" or anything youwant to display
I hope you choose the first option
Alexei Rodriguez
|
|
|
|
|
hi
please tel me how can i use a class or library or code for changing the contrast and sharpness of an image?
warm regards
|
|
|
|
|
You'll either have to use a third party image manipulation library or write one yourself in C# or C++. VB.NET can do it, but doesn't support pointers, so it's very slow at it.
Search the articles for "Image Processing for Dummies" for some examples by Christian Graus.
|
|
|
|
|
There's a VB.NET sample program called 'Fotovision', from Microsoft. It shows how to do contrast using built in GDI+ stuff. I've not seen an approach for sharpness that doesn't involve using C#, as per my articles ( thanks for the plug, Dave :P )
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 have a form with three numericupdown control and two text box and i bound that controls to a sql data source with a table adapter, how can i change and update the values of that controls in data base?
warm regards
|
|
|
|
|
Call the EndEdit method on your BindingSource object then call the Update method on your TableAdapter.
|
|
|
|
|
thank you for reply but
i use this method but there is some thing wrong and and error code has been generated when i use it the error is : update requires a valid update command when passed datarow collection with modified rows.
where the problem?
|
|
|
|
|
There are three common causes of this problem.
Either the TableAdapter was configured to use a stored procedure in your database, or the adapters GenerateDBDirectMethods property is set to False , or the table doesn't have a primary key uniquely identifying each row in the table.
If your SQL for the adapter is merely using the results of a stored procedure, you'll have to change the TableAdpater and give it the SQL commands (UPDATE, INSERT, DELETE) to use to update each row in the database from the changes in your datatable/dataset.
Fixing the GenerateDbDirectMethods problem is easy. All you have to do is change the checkbox in the Dataset Designer and resave the dataset to recreate the TableAdapter.
If your database table doesn't have a primary key, you'll have to add one to use the TableAdapter.
|
|
|
|
|
I need to write a script that will run every time someone tries to log off or shutdown a computer. In the past people have logged off computers while QE testing or automation on virtual machines were running. So it would always be a real pain when these VMs were shut off without warning. I need to write a script that would check for VMware’s executable file (vmware-vmx.exe) and (if the process is found) prompt a warning to the user and stop them from shutting down or logging off.
I’ve done A LOT of research on the internet about logoff/shutdown scripts, posted on message boards and I’ve emailed people that I know. However, I haven't been able to find any examples. I’ve found three different API calls/messages and I really don’t know which one I should use. I can’t move forward with my scripts until I do:
AbortSystemShutdown - This call aborts a shutdown initiated by InitiateSystemSutdown or InitiateSystemShutdownEx calls. ASS is thrown during the timeout period specified by ISS or ISSE. I don’t know if it will work for the console session since ISS and ISSE are only used in RDP connections.
ExitWindowsEx - Can shutdown, logoff, or restart a computer and pass reasons to the event log as to why any of these happened. I havn't found an API that aborts this call. I know that EWE sends the WM_QUERYENDSESSION message which can potentially abort a logoff/shutdown if the a value of “0” is returned. How do I respond to this message with “0”? I haven’t found any examples.
SystemEvents.SessionEnding - Can cancel shutdown
My qualms: can’t cancel logoff and too many caveats: console apps don’t raise this event, cancel only works sometimes, and there’s no guarantee this event will fire before the closing event fires.
I would really appreciate some help and feedback.
P.S. Just in case your wondering, I’m aware of the fact that I can’t directly call an API from a script and that I have to use either MS Office as proxy to load the code into a macro to make the calls or use an ActiveX control to act as a wrapper to make the calls
|
|
|
|
|
This isn't going to be a very helpful answer, I'm afraid, but if the VMs need to be running independently of the user, and can be interrupted by a user logging off or shutting down his machine, why are they being run on the user's machine at all? Stick a copy of VMWare server (free) on a server in the corner of the room somewhere and make everyone RDP to the machine. Set the RDP policies to disallow people shutting down the box, and job done.
|
|
|
|