|
Hi guys not exactly sure if parsing is the right terminology but I was wondering if someone can help me understand what I need to do. Here is what I hope my program to do...and also where I am stuck.
The program should be very simple containing only 1 textbox, 1 button, and one label to display the result.
The object of the program is to assign a number to each letter in the alphabet for example a=1 b=2 c=3 etc. and then calculate the textbox based on the letters it contains. the display the result in label1.text
when u fill in the textbox and press the button I want to be able to read the textbox value and parse each letter so that they can be added up based on their number value
right now on my form I have
Dim aa as integer = 1
dim bb as integer = 2
all the way to zz
Dim zz as integer = 26
in the button I have only
dim calctext as string = textbox1.text
now i guess i need to parse calctext somehow and store their values or add them directly. Just not sure where to start here and what the best way would be.
I guess my last question is on the form where i delcared aa and bb as integers etc. I used double letters like aa and bb because I didn't know if there would be conflict later on with the parsed variables...would there be?
Thanks in advance guys for any input...I'd appreciate a nudge in the right direction for the commands I should use. I learn best by trying.
|
|
|
|
|
1. First you should store the corresponding alphabet and number pair in a Dictionary. Not saying defining them from aa to zz won't work, but using Dictionary allows you to expand later on. You need to initialize the Dictionary, though.
2. Then you should break down the text in the textbox into an array of char (or string). You can use List for that too.
3. You go through the array of char or string, find the corresponding alphabet in the Dictionary, get the integet number assigned, and add the number to a count.
4. Display the count in the label.
|
|
|
|
|
Hi and thankyou very much for the response...but I am sorry maybe I didn't express my needs properly. I understand I need to breakdown the textbox into seperate letters...I just don't know the command I should be using...is it PARSE? or split or what...i'm just lost I don't know if I'll ever get this there is so much to know.
|
|
|
|
|
You can use a loop and SubString to go thru each char (as string), or you can use .Text.ToCharArray to generate an array of char, then go thru the array of char.
|
|
|
|
|
hi,
please help me, i want to make an application which implement linq features (linq to sql,linq to object and linq to xml) nah, what kind of application would be best for it ? since i have to use xml (linq to xml), is that mean i have to build a web application ? please help me for idea... any suggestion will be a great help.
thank you very much,
ganero
|
|
|
|
|
ganero wrote: since i have to use xml (linq to xml), is that mean i have to build a web application ?
This question tells me you want to play with LINQ for the sake of it, but don't have a grasp on basics. No, XML is not web only.
I'd recommend working through a beginner book and doing hte LINQ chapter when you get to it.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
thanks Christ, yes like you said, i want to experiment linq but i need to implement it in one application ( 'I MUST BUILD an APPLICATION' ) and so the problem is i don't know what to make... i mean, idea, if you don't mind, i'm asking for a application title - could you give me some ?
thank you
|
|
|
|
|
I have a list box and a combo box that both allow you to
select a teachers name from a list. They are on different panels that show on the form at different times. I created a dataTable named dtTeachName that only holds the teacher name and id. I am attempting to populate both of these controls with the saem information. At first I loaded both of these from the same dataTable, but when I do that the teacher names will dissapear in the list box. I even put an if statement that said that that list box wont populate unless the panel it is on is visible. When I do that the program freezes.
Has anyone run into this problem before?
Here is my code.
' fill the teachers checked list box
cboSelectTeacher.DataSource = dtTeachName
cboSelectTeacher.DisplayMember = "teach_name"
cboSelectTeacher.ValueMember = "teach_id"
' fill the teachers checked list box
lstTeachers.DataSource = dtTeachName
lstTeachers.DisplayMember = "teach_name"
lstTeachers.ValueMember = "teach_id"
|
|
|
|
|
You can't bind two controls to the same source, you need to make a copy.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
How do I make a copy? Do I just do another query or literally make a copy?
|
|
|
|
|
you can use the CLone method to make a copy, I believe that makes a deep copy. Otherwise, you'd run your query again, but I'd try Clone() first.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I tried to run the query again and the program still freezes. When I ran the query again I also populated a completely different dataTable and it still didn't work. Then I tried to create a clone of the original dataTable and then the list box will populate and the program does not freeze, but the combo box does not populate.
|
|
|
|
|
The app freezing is not a typical symptom of what goes wrong when you reuse a datasource. Usually changing one control just causes te other to change too. My guess is that you're not cloning it properly, and your source is empty. And, I would guess that you have code running on a selected index change which is being run by the databinding, and causing it ti freeze. If you break out or if you set breakpoints around the related code when you debug, wat happens ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Right now it is not freezing. I just need to figure out how to populate this combo box with the teacher names.
Here is my code for cloning the datasource. I tried doing it several ways.
' query
tableName = "tbl_teachers"
dtTeachName = generalQuery()
' fill the teachers checked list box
lstTeachers.DataSource = dtTeachName
lstTeachers.DisplayMember = "teach_name"
lstTeachers.ValueMember = "teach_id"
cboSchedDur.SelectedItem = "This Week"
'End If
' fill the teachers checked list box
dtTNameClone = dtTeachName.Clone()
cboSelectTeacher.DataSource = dtTNameClone
cboSelectTeacher.DisplayMember = "teach_name"
cboSelectTeacher.ValueMember = "teach_id"
|
|
|
|
|
does dtTeachName contain any data ? If it does, it should be showing.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
It does show data. I populated another list box from the data, but when I make the copy it does not fill the combo box.
The list box and the combo box are filled in 2 different sub procedures. The dataTables that I am using are declared globally in a module as public.
|
|
|
|
|
AAGTHosting wrote: The dataTables that I am using are declared globally in a module as public.
Well, they should exist solely for the control that's using them, making one global like htat is a poor design.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I tried declaring local dataTables and it still does not work. I just ran the same query again and the list box populated, but when I click on the students button to go to that panel all the controls on the panel do not come up.
Here is my query. Would it be better for me to use a GetDataBy query instead of a fillBy? The GetDataBy method returns a dataTable.
|
|
|
|
|
Where is your query ?
Sounds like what you're really saying is that you have a button event which is not working, have you set a breakpoint in there ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
This only seems to happen when I try to populate the second teacher list box. If I comment out the code to bind a source to the teacher combo box then only the first name on the list of teachers shows up in the teacher list box, then when I click on the students button one of my list boxes shows up, that is not filled dynamically and you can't select a type of student.
Should I use multiple datasets so I don't have multiple controls getting info from the tables in the dataset?
|
|
|
|
|
you can bind multiple combo boxes to the same dataTable if each has its own binding source
|
|
|
|
|
I am getting error in the following code...
---------------------------------------------------------------------------------------
<br />
<br />
odbAdapter = New OleDbDataAdapter("select * from tblEmployeeAttendance", objConnection)<br />
<br />
ap.Fill(ds, "EmpAttendance")<br />
<br />
Dim i As Integer = ds.Tables(0).Rows.Count
---------------------------------------------------------------------------------------
When I add a watch on "ds.Tables(0).Rows" add check its Items property....
I see "In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user."
Following is the structure of tblEmployeeAttendance table in an MS Acceess database.
ID - AutoNumber
EmployeeCode - Text
AttendanceDate - date/Time
AttendanceCode - Text
AttendanceDescription - Text
AttendanceDescriptionDate - Date/Time
-------------------------------------------------
Do you have any idea about the cause of this error...?
Thanks,
Arun
“The woods are lovely, dark and deep. But I have promises to keep, and miles to go before I sleep.”
|
|
|
|
|
You have to supply the row index to view the data with in. In this case you would have to watch ds.Tables(0).Rows(0).ItemArray in order to see the first row in the table.
But if you have Visual Studio 2005 you can do a QuickWatch and click on the magnify glass icon to actually load the whole database into a grid to view the data...not available in VS2003 though.
Hope this helps.
|
|
|
|
|
Thanks for your help.
Now, using
Dim i As String = dsToupdate.Tables(0).Rows(0).Item(0)
returns correct value.
But how can I use it in looping through each row in the data set...
Currently my code looks like this...
For Each dr As DataRow In dsToupdate.Tables(0).Rows<br />
If (dsToupdate.Tables(0).Rows.Count > 0 And (Not (dr.Item("EAR_Employee_Code") Is Nothing))) Then<br />
<br />
dr.Item("EAR_Employee_Code") = strEmpCode<br />
dr.Item("EAR_Attendance_Date") = dtpAttendanceDate.Value<br />
dr.Item("EAR_Attendance_Code") = strIsPresent<br />
dr.Item("EAR_Attendance_Desc") = strDesc<br />
dr.Item("EAR_Attendance_DescDate") = strDescdate<br />
<br />
End If<br />
Next
------------------
can you please provide me a hint how to change the above code to access each item in each data row...?
I am using VS2005.
Thanks,
Arun
“The woods are lovely, dark and deep. But I have promises to keep, and miles to go before I sleep.”
|
|
|
|
|
I guess I really don't understand what you are asking. I think you are doing it correctly. You do not need the dsToupdate.Tables(0).Rows.Count > 0 check because the For Each statement will not run if the table is empty. But I don't know of any other way to access each column in the data row. It's easier to user the column names like you did here, than to use the indexes of the columns. Unless you are setting all of the items to the same number, in which case you can loop through the columns inside your row loop...by adding something like this:
For Each dc as DataColumn in dsToupdate.Tables(0).Columns<br />
dr.Item(dc.Name) = "VALUE"<br />
Next
Hope this helps.
|
|
|
|