|
some calculators work that way; others don't want to perform a second operation until a new number has been entered.
decide what functionality you want, then implement it.
if necessary keep track of what happened most recently (enter number parts, i.e. digits, minus sign, period) or click operator.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
i am a visual basic programmer. pls i need to deploy my database along with my project. i try but failed. please any one with this code should help me. Thanks.
|
|
|
|
|
"i need help" is a stupid subject, everybody needs help.
the word is "please", not "pls".
"i try but failed". wait, let me use my mind reading powers to see where exactly you failed and what your problem is, then sending the solution from my brain straight into your computer.
"please any one with this code should help me." which code? how could anybody help you, if you don't describe your problem?
read this: How to get an answer to your question.[^]
"I love deadlines. I like the whooshing sound they make as they fly by." (DNA)
|
|
|
|
|
Please provide more information like what kind of database you have. You could also post the code you tried and tell us what error you got or how it failed. Otherwise I'd suggest you start by searching CP articles[^].
|
|
|
|
|
Hello all,
am been looking alot and didnt find what am looking for, i got a newsticker reads xml file, whats the best method to track users, i dont want users to register, i just need to know how many users online and make satistics, my idea is another windows form that receive info from the news ticker once users run like IP address and time and date, is this possible? thanks in advance
|
|
|
|
|
Well, if your news ticker is getting it's data from a news site, then you would need to write code for it to connect to the news site and your server. It seems a bit unnecessary to me.
"The GNOME desktop is as bad as a virus."
^-^-^-@@-^-^-^
(..)-----;
||---||
^^ ^^
Moose.
|
|
|
|
|
Ok, I have the labels working properly on each tab. I can change them based upon the sequence of orders for each item placed the day before. (I am manually adjusting that now). I need to create the Function MaterialSave(). Each item on each tab has 5 textboxes for New (A), Good (B1), Good (B2), Good (C) or Junk (F). First textbox is txtRodF_0, txtRodC_0, txtRodB2_0 and next row is txtRodF_1, txtRodC_1, txtRodB2_1, etc. I need to store the materialID (a GUID) that is stored in the lblRods_x.Tag property, the name of the text box txtRodC_0.name and the number of units being traded.
A person can trade/sell 15 units of txtRodF_0 and 20 units of txtRodB2_0 and any combination od trades/sells per tab per Material Transfer form. Each agent can do 100 or so forms per day.
I tried doing a multi-dimensional array and then a collection and have bombed out on each of them. Then I was researching and came across maybe using a Material Class with 3 properties and I just add class member everytime a textbox loses focus after an amount has been entered. I can then save the class members one by one to the material table on the form_close event. When a new form is pulled up it creates a new material class all over.
Any ideas or suggestions, better/faster way of doing this?
|
|
|
|
|
Maybe not a bad idea,
Public Class Material
Private _id As String
Private _name As String
Private _value As Double
Public Property ID() As String
Get
Return _id
End Get
Set(ByVal value As String)
_id = value
End Set
End Property
Public Property Name() As String
Get
Return _id
End Get
Set(ByVal value As String)
_id = value
End Set
End Property
Public Property ID() As String
Get
Return _id
End Get
Set(ByVal value As String)
_id = value
End Set
End Property
Public Sub New(ByVal id As String, ByVal name As String, _
ByVal value As Double)
With Me
ID = id
Name = name
Value = value
End With
End Sub
End Class
Now if you use your Material Class in a Generic List that you declare as a Form Level variable Public MatList As List(Of Material) , you will be able to retreive, and add items to your hearts content. Then when the form closes, save your data, iterating through the items in the MatList
Hope this helps.
I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
Thanks, I seem to have that part working now. got another problwm which I don't seem to remember that in VB6. Started another post for it titled: "Lost_focus and save button"
|
|
|
|
|
I have a table of 13 items that I need to display in sequence. The sequence can change from day to day based upon the previous days usage. One day the number 1 item may be 3/4" concrete lined rod, the next day that may be 5th and 5/8" SMPC may be the number one item. I pull the material from the table in the sequence order and then I want t fill in the label with the material name and the label tag property with the MaterialID which is a GUID. I found some code in a google search for creating a control array but I'm just not understanding it enough to get it to work in my project. The link for that is as follows:
http://vbnet.codenewbie.com/articles/vbnet/1555/Mimicking_VB6_Control_Arrays_in_VBNET-Page_1.html
My labels are named lblRods_0 to lblRods_12 and the code for loading them is:
Private Function LoadTabData() As Boolean
'We need to get the items for the frmLOL from the table Materials and load
'them into the text boxes in sequence. If user fills out anything we need to
'store it using the GUID stored in the tag property
'SELECT Materials.MaterialsID, Materials.Type, Materials.Sequence, Materials.Material
'FROM(Materials)
'ORDER BY Materials.Type, Materials.Sequence;
Try
gblConn = New OleDbConnection(JWIConnStr)
Dim daMaterial As New OleDbDataAdapter
Dim dsMaterial As New DataSet
Dim mySelectQuery As String = "SELECT MaterialsID, Type, Sequence, Material " & _
"FROM Materials " & _
"ORDER BY Type, Sequence;"
Dim myConnection As New OleDbConnection(JWIConnStr)
Dim myCommand As New OleDbCommand(mySelectQuery, myConnection)
myConnection.Open()
daMaterial.SelectCommand = myCommand
daMaterial.Fill(dsMaterial)
If Not dsMaterial.Tables(0).Rows.Count > 0 Then
MsgBox("Unable to locate MATERIALS. Please Cancel and retry later", MsgBoxStyle.OkOnly)
Exit Function
Else 'at least one record shows
Dim recCount As Integer
Dim dstbl As New DataTable
daMaterial.Fill(dstbl)
recCount = dsMaterial.Tables(0).Rows.Count
Dim rowNdx As Integer
Dim lblNdx As Integer
rowNdx = 0 'Set to zero index value for the dsMaterial tbl
lblNdx = 1
For Each Row In dstbl.Rows
If rowNdx = recCount Then
Exit For
End If
'Dim Labels As Label() = ControlArrayUtils.getControlArray(Me, "lblRods")
Dim lblRods As Label() = ControlArrayUtils.getControlArray(Me, "lblRods")
'Dim lblRods() As Label
'lblRods = ControlArrayUtils.getControlArray(Me, "Label")
'lblRods = ControlArrayUtils.getControlArray(Me, "lblRods")
lblRods(lblNdx).Tag = dsMaterial.Tables(0).Rows(rowNdx)("MaterialsID").ToString()
lblRods(lblNdx).Text = dsMaterial.Tables(0).Rows(rowNdx)("Material").ToString()
rowNdx = rowNdx + 1 'keep track of where we are at
lblNdx = lblNdx + 1
Next
End If
Catch ex As Exception
Debug.Print(MsgBox(ex.ToString))
End Try
End Function
Public Class ControlArrayUtils
'Converts same type of controls on a form to a control
'array by using the notation ControlName_1, ControlName_2,
'where the _ can be replaced by any separator string
Public Shared Function getControlArray( _
ByVal frm As Windows.Forms.Form, _
ByVal controlName As String, _
Optional ByVal separator As String = "_") As System.Array
Dim i As Short
Dim startOfIndex As Short
Dim alist As New ArrayList
Dim controlType As System.Type
Dim ctl As System.Windows.Forms.Control
Dim ctrls() As System.Windows.Forms.Control
Dim strSuffix As String
Dim maxIndex As Short = -1 'Default
'Loop through all controls, looking for
'controls with the matching name pattern
'Find the highest indexed control
For Each ctl In frm.Controls
startOfIndex = ctl.Name.ToLower.IndexOf( _
controlName.ToLower & separator)
If startOfIndex = 0 Then
'If startOfIndex = -1 Then
strSuffix = ctl.Name.Substring(controlName.Length)
'Check that the suffix is an
' integer (index of the array)
If IsInteger(strSuffix) Then
If Val(strSuffix) > maxIndex Then _
maxIndex = Val(strSuffix) 'Find the highest
'indexed Element
End If
End If
Next ctl
'Add to the list of controls in correct order
If maxIndex > -1 Then
For i = 0 To maxIndex
Dim aControl As Control = _
getControlFromName(frm, controlName, i, separator)
If Not (aControl Is Nothing) Then
'Save the object Type (uses the last
'control found as the Type)
controlType = aControl.GetType
End If
alist.Add(aControl)
Next
End If
Return alist.ToArray(controlType)
End Function
'Converts any type of like named controls on a form
'to a control array by using the notation ControlName_1,
'ControlName_2, where the _ can be replaced by any
'separator string
Public Shared Function getMixedControlArray( _
ByVal frm As Windows.Forms.Form, ByVal controlName As String, _
Optional ByVal separator As String = "") As Control()
Dim i As Short
Dim startOfIndex As Short
Dim alist As New ArrayList
Dim controlType As System.Type
Dim ctl As System.Windows.Forms.Control
Dim ctrls() As System.Windows.Forms.Control
Dim strSuffix As String
Dim maxIndex As Short = -1 'Default
'Loop through all controls, looking for controls
'with the matching name pattern
'Find the highest indexed control
For Each ctl In frm.Controls
startOfIndex = ctl.Name.ToLower.IndexOf( _
controlName.ToLower & separator)
If startOfIndex = 0 Then
strSuffix = ctl.Name.Substring(controlName.Length)
'Check that the suffix is an integer
'(index of the array)
If IsInteger(strSuffix) Then
If Val(strSuffix) > maxIndex Then _
maxIndex = Val(strSuffix) 'Find the highest
'indexed Element
End If
End If
Next ctl
'Add to the list of controls in correct order
If maxIndex > -1 Then
For i = 0 To maxIndex
Dim aControl As Control = getControlFromName(frm, _
controlName, i, separator)
alist.Add(aControl)
Next
End If
Return alist.ToArray(GetType(Control))
End Function
Private Shared Function getControlFromName( _
ByRef frm As Windows.Forms.Form, _
ByVal controlName As String, ByVal index As Short, _
ByVal separator As String) As System.Windows.Forms.Control
controlName = controlName & separator & index
For Each ctl As Control In frm.Controls
If String.Compare(ctl.Name, controlName, True) = 0 Then
Return ctl
End If
Next ctl
Return Nothing 'Could not find this control by name
End Function
Private Shared Function IsInteger(ByVal Value As String) As Boolean
If Value = "" Then Return False
For Each chr As Char In Value
If Not Char.IsDigit(chr) Then
Return False
End If
Next
Return True
End Function
End Class
I get the error message: System.ArgumentNullException:Value cannot be null. Parameter name:type at System.Collections.ArrayList.ToArray(Type type) at JWI.ControlArrayUtils.getControlArray(Form frm String controlName,String separator) in C:\JWI\JWI\JWI\ControlArrayUtils.vb:line 56 at JWI.frmLOL.LoadTabData() in c:\JWI\JWI\JWI\frmLOL.vb line 332
Any assistance in understanding the error message and how to get this to work would be greatly appreciated. I've tried about 2 dozen versions of calling the array utility but no luck yet.
Thanks,
Larry
|
|
|
|
|
tell your IDE to always display line numbers (Visual Studio Tricks[^]).
go to the offending line.
take the message literally: some argument is null where it should not be.
now fix it.
if you still don't see it, use a debug run, and watch the values in the offending line.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
I have no problem picking up the line number and col number from the bottom of the IDE. It very clearly shows it.
What I am not understanding is WHY the code is not returning the controlType? This loop (line numbers added for your convienance) from lines 43 to 56 should pick up the type as being a Label from what was defined and pased into it. I would imagine that is what appears to be Null - it doesn't pick up that lblRods_ is a label even though I have tried both of these combinations:
Dim Labels As Label() = ControlArrayUtils.getControlArray(Me, "lblRods")
Dim lblRods As Label() = ControlArrayUtils.getControlArray(Me, "lblRods")
and I don't know how many other combinations. My conclusion is an error in the original code- but that is because I am not certain. I would hope somebody with more experience than myself would be able to examine and determine if that is the case and possible suggest a solution. I'm assuming it would return the controlType as Label and not Null
43 If maxIndex > -1 Then
44
45 For i = 0 To maxIndex
46 Dim aControl As Control = _
47 getControlFromName(frm, controlName, i, separator)
48 If Not (aControl Is Nothing) Then
49 'Save the object Type (uses the last
50 'control found as the Type)
51 controlType = aControl.GetType
52 End If
53 alist.Add(aControl)
54 Next
55 End If
56 Return alist.ToArray(controlType)
|
|
|
|
|
From the MSDN documentation on ArrayList.ToArray(Type) it is clear an ArgumentNullException will be thrown when the type is Nothing. So here are two ways to get that, assuming controlType starts at Nothing:
1. the if fails in line 43
2. getControlFromName in line 47 return Nothing for any of a million reasons (maybe controlName does not contain what you hope for)
I must say your code snippet (lines 43-56) is a bit bizarre; either you expect to find a single control, then why would you need an ArrayList? or you expect multiple controls, but then the last one decides on the type of all of them?? This could work fine under your current conditions, I can't tell, it doesn't look very robust. And, as stated before, there may be zero matches, resulting in line 56 causing an Exception.
FWIW: I advise you start each VB file with "Option Strict On". It will cause some pain as now the system complains a lot, but it will force you to improve your code and in the end save lots of debugging time.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
I have to agree...that is some bizarre code.
So, you have 13 labels that all start with lblRods. So then, you're running the function to return an array of controls that all start with lblRods. All of that is great.
Your problem is with the getControlArray code. Think about what it should do and then look at exactly what it does.
It should loop through all of the controls on the form and see if the control starts with the value you passed in, in this case "lblRods". If it does start with that, then you want to add it to the array.
Here's what your code does. You search through the controls and are looking for the highest index of the controls. So, your code matches each control that starts with lblRods and instead of adding that control to an array, you instead, see if it's index is the highest index so far.
Then, if the index is greater than -1, you go through and call GetControlFromName which will return a control with the exact name that you passed it. In this case, you passed it lblRods. It will never return a control with that exact name because it doesn't exist.
So, what happens is that aList will have nothing in it and controlType will equal Nothing .
Why didn't you just add the controls to the list when you found them in the first for each loop? That's all you needed to do. And you need to make sure that the array isn't empty before returning something. How about a re-write:
Public Shared Function getControlArray(ByVal frm As System.Windows.Forms.Form, _
ByVal controlName As String, _
ByVal TypeToReturn As Type, _
Optional ByVal separator As String = "") As Control()
Dim aList As New ArrayList
For Each ctrl As Control In frm.Controls
If ctrl.Name.ToLower.StartsWith(controlName.ToLower & separator) And _
ctrl.GetType = TypeToReturn Then
aList.Add(ctrl)
End If
Next
If aList.Count = 0 Then
Return Nothing
Else
Return aList.ToArray(TypeToReturn)
End If
End Function
it's that easy...you were making it too complicated.
If you're only wanting to return a single type, then you really need to make sure to check that that type is the right type. Obviously, you can know that the only thing with the name "lblRods" is going to be a label because you wrote it that way, but then why not just hard code the values, unless you're trying to make something that can be used in other places.
When you call it then, just do:
Dim labels() as Label = GetControlArray(Me, "lblRods", GetType(Label))
modified on Thursday, May 27, 2010 2:34 PM
|
|
|
|
|
Thanks, the last two replies help me to understand what is going on a little bit better. I'm wanting an easier way to handle this. I have a tab on the form with 4 tabs and on each tab the number of items that will vary from day to day : 13 Rods, 11 Tubes, 10 Equip, and 9 Misc. So hard coding it is not really desirable.
I wonder if it shows Null or nothing as a result of the labels being on the tab. When I ran this:
For Each Row In dstbl.Rows
If rowNdx = recCount Then
Exit For
End If
For Each c As Control In Me.TabPage1.Controls
If c.Name = "lblRods_" & lblNdx Then
c.Tag = dsMaterial.Tables(0).Rows(rowNdx)("MaterialsID").ToString()
c.Text = dsMaterial.Tables(0).Rows(rowNdx)("Material").ToString()
End If
Next
rowNdx = rowNdx + 1 'keep track of where we are at
lblNdx = lblNdx + 1
Next
It did not work as For Each c As Control In Me.Controls Debug.Print showed me the names of each control but I just got tabLOL but not tabLOL.TabPage1 so when I hard coded it fills in properly.
So I changed to having 4 separate functions:
Private Function LoadTab1Data() As Boolean
Private Function LoadTab2Data() As Boolean
Private Function LoadTab3Data() As Boolean
Private Function LoadTab4Data() As Boolean
And it seems to be working when I change the statement:
Dim mySelectQuery As String = "SELECT MaterialsID, Type, Sequence, Material " & _
"FROM Materials " & _
"WHERE Type = 2 " & _
"ORDER BY Type, Sequence;"
and change the Type.
Would still like to modularize it more and make it one Function that goes through the data 4 times and fills in each tab page properly.
Works clumsily now, but still hoping to refine it,
Larry
|
|
|
|
|
Your problem with that is what you thought it was. frm only knows about the controls added directly to it. Containers have their own controls and the object that the container is added to knows nothing directly about it's children.
You can access it through Me.TabPage1 because it's a variable that was declared within the form, but it was never added to the forms control collection, it was added to the tabControl's control collection.
If you want to be able to search through children controls as well, you could do that using a modified version of what I posted earlier.
Public Shared Function getControlArray(ByVal baseControl As Control, _
ByVal controlName As String, _
ByVal TypeToReturn As Type, _
Optional ByVal separator As String = "") As Control()
Dim aList As New ArrayList
For Each ctrl As Control In baseControl.Controls
If ctrl.Controls.Count > 0 Then
For Each item As Control In getControlArray(ctrl, controlName, TypeToReturn, separator)
aList.Add(item)
Next
End If
If ctrl.Name.ToLower.StartsWith(controlName.ToLower & separator) And _
ctrl.GetType = TypeToReturn Then
aList.Add(ctrl)
End If
Next
Return aList.ToArray(TypeToReturn)
End Function
I just made the Form being passed in a Control instead and check that control for any children, then it recursively checks the children. I tested it by adding a TabControl and several Labels to a TabPage and it works as expected.
You can also just pass in the TabPage if you know that the items will only be on that TabPage.
|
|
|
|
|
|
How are you trying to do this at the moment?
Where is it failing?
Why are you trying to 'pinch' a captcha, there are numerous articles on how to produce your own.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
Hi..all Codeproject members...
I got a vb.net code i got from codeproject..
this code is a class to load a sqldatareader into a listview
and this is the code
Imports System.Data.SqlClient
Public Class ListViewData
Public Sub FillListView(ByRef MyListView As ListView, _
ByRef myData As SqlDataReader)
Dim lvwColumn As ColumnHeader
Dim itmListItem As ListViewItem
Dim shtCntr As Short
MyListView.Clear()
For shtCntr = 0 To myData.FieldCount() - 1
'If shtCntr = 1 Then Continue For
lvwColumn = New ColumnHeader()
lvwColumn.Text = myData.GetName(shtCntr)
MyListView.Columns.Add(lvwColumn)
If shtCntr = 0 Then lvwColumn.Width = 125
If shtCntr = 1 Then lvwColumn.Width = 300
Next
Do While myData.Read
itmListItem = New ListViewItem()
itmListItem.Text = myData(0)
For shtCntr = 1 To myData.FieldCount() - 1
'If shtCntr = 1 Then Continue For
If myData.IsDBNull(shtCntr) Then
itmListItem.SubItems.Add("")
Else
itmListItem.SubItems.Add(myData.GetString(shtCntr))
End If
Next shtCntr
MyListView.Items.Add(itmListItem)
Loop
End Sub
End Class
And this is how i use this code
Private Sub Usage_ListItem_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As SqlConnection = New SqlConnection(constr)
Dim query As String
query = "SELECT ItemCode [Item Code], ItemName[Item Name] FROM IC_ITEMS"
con.Open()
Dim comtext As SqlCommand = New SqlCommand()
comtext.Connection = con
comtext.CommandText = query
Dim reader As SqlDataReader
reader = comtext.ExecuteReader
Dim testlist As ListViewData = New ListViewData
testlist.FillListView(ListView1, reader)
comtext = Nothing
con.Close()
End Sub
The problem is i just want to load only ItemName Reader into the listview..
how can i modify this code
at least
thx for codeproject members attention..
|
|
|
|
|
Your best bet is to ask this on the forum of the article where you got the code.
But I'll take as stab at it.
If you only want the itemname column in your listview then all you have to do is change your SQL statement
from:
"SELECT ItemCode [Item Code], ItemName[Item Name] FROM IC_ITEMS"
to:
"SELECT ItemName[Item Name] FROM IC_ITEMS"
and you should have only your itemname column in the listview
|
|
|
|
|
i mean i want to use the itemcode into another control
|
|
|
|
|
If you want to use the different items in different controls, then something like this:
reader = comtext.ExecuteReader
Dim itemCodeIndex, itemNameIndex As Integer
itemCodeIndex = reader.GetOrdinal("ItemCode")
itemNameIndex = reader.GetOrdinal("ItemName")
While reader.Read()
ListView1.Items.Add(reader.GetValue(itemCodeIndex))
ListView2.Items.Add(reader.GetValue(itemNameIndex))
End While
|
|
|
|
|
and how is i have 3 reader and i want use 2 reader into list view 1
and 1 reader into listview2
|
|
|
|
|
I don't understand your question
|
|
|
|
|
ok...this all completely done...thx
|
|
|
|
|