|
The question you first need to ask yourself is, how large a number can the user possibly enter? In other words, you will first have to determine how many positions you will have to report on (singles, tens, hundreds, thousands, tenthousands, hundredthousands, etc). In yet other words, how many textboxes will you need to put on your form?
So as Liqz suggested, it might be best to use Chars, and an array first, before using a loop.
Something like:
Dim PositionsArray() As Char = TextBox1.Text.ToCharArray
Now you can easily determine the number of characters:
Dim AmountOfPositions As Integer = PositionsArray.Length
Now you almost know how many positions you will have to handle. But what if we use your example: 105,749 ? This has a comma in the middle, which is also a position, but not a number.
Here you could use a For Each loop:
For Each c As Char In PositionsArray
'This will loop through the characters from left to right'
'Then play around with the possiblities of the Char type:'
If Not Char.IsDigit(c) Then
MsgBox("I found something other than a number (" & c.ToString & ")" & _
" at index: " & Array.IndexOf(PositionsArray, c))
End If
Next
Next you could look into the Case statement. like Steven suggested below.
My advice is free, and you may get what you paid for.
|
|
|
|
|
First of all thank u so much for all the help
I tried using the case statement but when I tried to pass the myNumber.Units, Tens, and so on to display in a separate
textbox it wouldn't display anything.
Case 1
myNumber.Units = sEnteredNumber.SubString(idx, 1)
Textbox1.text = myNumber.Units
This is what i tried doing to display to the user what the ones, tens and so on were but it wouldn't display anything?
|
|
|
|
|
First create a structure to hold the results
Structure NumberBreakDown
Dim Units as byte
Dim Tens as byte
Dim Hundreds as byte
Dim Thousands as integer
End Struture
Then
Dim myNumber as NumberBreakDown
Dim position as integer = 0
Dim sEnteredNumber as string = enteredNumberTextBox.Text.Trim
For idx as byte = sEnteredNumber.Length -1 to 0
position += 1
Select Case position
Case 1
myNumber.Units = sEnteredNumber.SubString(idx, 1)
Case 2
myNumber.Tens = sEnteredNumber.SubString(idx, 1)
Case 3
myNumber.Hundreds = sEnteredNumber.SubString(idx, 1)
Case Else
myNumber.Thousands = sEnteredNumber.SubString(0, sEnteredNumber.Length - Position +1)
End Select
Next
The above obviously does not handle commas and decimal places, but could easily be modified to.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
I tried using this case statement but when I tried to pass the myNumber.Units, Tens, and so on to display in a separate
textbox it wouldn't display anything.
Case 1
myNumber.Units = sEnteredNumber.SubString(idx, 1)
Textbox1.text = myNumber.Units
This is what i tried doing to display to the user what the ones, tens and so on were but it wouldn't display anything?
Thank you for all the help
|
|
|
|
|
I think there may be a small omission in Steven's code (and I apologise now if I am wrong, Steven!). But I think you need to tell the loop to count backwards, otherwise the loop is going to count up from the length of string - 1 to 0. Try adding 'Step -1' to the end of for statement.
|
|
|
|
|
ok first of all THANK U STEVEN the code worked!
it was just missin that step -1 as u had stated
but the only thing is if i try to enter lets say
123456, just like that
the thousands place will only pick up 1, not 123
do i need to do a test if the number entered is
more then 4 digits long?
thank u everyone!
|
|
|
|
|
Try changing the 'Case Else' statement to this:
Case Else
myNumber.Thousands = sEnteredNumber.SubString(0, Position - 3)
|
|
|
|
|
Thanks it worked and i appreciate all da help!!!
|
|
|
|
|
Could you post the entire code of the loop, and everything inside it, please?
My advice is free, and you may get what you paid for.
|
|
|
|
|
well im at work right now and dont have the code on me
but it was just like stevens code
but the good thing is i got it to work
but the only thing im still trying to figure out
is when a user enters lets say: 12345
the thousands should show 12
but right now it onlh will display 1 only
and the hundreds and ones and tens do work properly
i was thinking maybe an if statement???
the only change i made to stevns case was added
step -1 to the end of the for loop
|
|
|
|
|
Well, if you parse it into an actual integer, instead of using it as a string, it gets easier, using a combination of the "mod" (modulus) and "div" (division without remainder) operators...
123,456 mod 1000 = 456
456 div 100 = 4
So your "hundreds" place is (X mod 1000 div 100)
If you want to get more than just the one digit, like your other replies, skip the "mod" step and just run it through a div.
123,456 div 100 = 123
|
|
|
|
|
You can use String.ToCharArray method. Then use TryParse to check if the character is an integer and then display it.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Hello,
I am writting an aplication in VB.NET (not a website)
I would like to cache a datatable to save time when loading program, I will fill the datatable according to cache.
Here my code:
Imports System.Web.HttpRuntime
dtSynchronize = DirectCast(Cache("dtSynchronize"), DataTable)
If dtSynchronize Is Nothing Then
dtSynchronize = New DataTable
dtSynchronize.Columns.Add("EntryID", System.Type.GetType("System.String"))
dtSynchronize.Columns.Add("SyncData", System.Type.GetType("System.String"))
dtSynchronize.Columns.Add("StoreID", System.Type.GetType("System.String"))
End If
dtSynchronize.Rows.Clear()
dtSynchronize.Rows.Add("1", "2", "3")
Cache.Insert("dtSynchronize", dtSynchronize)
It works fine but when I am closing the application and opening it again, I expect that after the first line of code the dtSynchronize will not be Nothing but it is.
The cache is not saved.
Thank you
Shay Noy
modified on Tuesday, September 8, 2009 5:41 AM
|
|
|
|
|
I found other solution by storing the datatble in a file and it works fine. Although, if someone has solution for storing it in a cache, please advise
Thank you
Shay Noy
|
|
|
|
|
As a cache is only an area of memory it will disappear when your application closes unless you save it to disk or a database
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Thank you, I understood it later, I though it is the same cache like in ASP.net.
Shay Noy
|
|
|
|
|
Hi, I am fairly a newbie to vb.net and am developing an inventory control windows application for a client.
I am creating a search form for my application. This search form searches the categorys table and returns the results in a datagrid view. The search bit of it is working, however what i want it to do next is not working!
I have a button on the Search form called "Return Data". Once the search results have been displayed in the datagrid view, the user will then select/highlight the row that they need. They will then click on the "Return Data" button and this button should then return the selected row in the datagrid view and display it in another datagrid view on another form.
I am just finding it extremely difficicult to getting this sorted. I have not got anywhere with it. Any sample code would be most appreciated.
Thanks
|
|
|
|
|
ShabRaza wrote: Hi, I am fairly a newbie to vb.net and am developing an inventory control windows application for a client.
I pity the person who uses an inventory system written by a newbie. The world is insane.
ShabRaza wrote: Once the search results have been displayed in the datagrid view, the user will then select/highlight the row that they need. They will then click on the "Return Data" button and this button should then return the selected row in the datagrid view and display it in another datagrid view on another form.
The can select more than one row ? This Ui sounds odd, but you can iterate over your rows and check which have the selected property set to true.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I pity immature people like you who make assumptions about others on a flip of a coin.
I wanted advice on helping me resolve a problem, not having someone make a dig at me. In the end you werent much useful and next time keep your opinions to yourself!
|
|
|
|
|
|
To Hurricane3000
First of all i would like to ask, who involved you in this conversation? cos i sure as hell didnt. The comment i made was only intended for the person who made those comments to me and I dont remember asking anyone else's opinion!
After having some difficulty reading your message, i think you need to go find out and evaluate the difference between a "playful comment" and "personal offence". Since when does it make a difference on your programming ability if you are "unable to understand difference between a "playful comment" and a "personal offence"! ". I think you need to get your head checked out. I think being a good programmer is dependant on your technical ability amongst other IMPORTANT factors and not minor and irrelevant things.
I do not wish to carry this conversation any further as it is pointless. so if you have any sense dont reply back.
|
|
|
|
|
I wish you to end soon your program ShabRaza.
Good night.
|
|
|
|
|
Hello
Are you having ID filds in DGV.If you having then u can easly send selected rows into another dgv on another form.
When you select that row then just get id of that row, and when return data button is clicked then add new row on other dgv and send value from one dgv to another dgv.
The another method is that check which row is select using selected = true. Create object of another form and access DGV using anohterformobj.Datagridview. and add selected records on another dgv.
Regards
DC
|
|
|
|
|
Actually their are several ways to do this depends upon the criteria and structure of the application
lets suppose you need to show
=-=-Item Code=-=-=-=-Item Name=-=-==-=-category Name=-=-=-=-=-=-Units=-=-=-=-=-=-Qty
on the Destination form then on your Search/Lookup Form you can have some other columns like
=-=-Item ID======Category ID-=-=-=-=--
but hide them along with your other columns and dont show them to the end user when user will select any row then it will bring with it that item id, category id etc.. take only Keys as hidden columns
you can take this id and then can make a query to get your desired results and can populate your fields,
will not recommend you to open Costly connections again and again means to go to the database and bring your information time to time
Dont bring information other then Keys in hidden columns because if their will be any change on that data lets say you had populated in your grid and some other user changed the item Name or some other information in this case you will have still old value in the grid so bring only the IDs as hidden column and then fetch your desired data from db
Best Of Regards,
SOFTDEV
Sad like books with torn pages, sad like unfinished stories ...
|
|
|
|
|
Hi all.
I am trying to check whether a process has terminated or not by its process id.
I put my code in a timer object to continuously check whether process has terminated or not.
code is :
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Process.GetProcessById(ProcessID).HasExited Then 'processId is publicly defined and doesn't store null value
Cursor = Cursors.Default
Timer1.Dispose()
msgbox("Process has been terminated")
End If
End Sub
but each time timer starts, it gives an "Access is Denied" error message at line
If Process.GetProcessById(ProcessID).HasExited Then
what should I do to check whether the process has terminated or not.
Thanks.
Gagan
|
|
|
|