Remove Trailing 0's
Hi all,
I have a bit of a problem. I'm calculating 2 multiplied numbers. One of the numbers is a quantity and the other is a price. The price can be a number with up to 5 decimal places (I.e.: 1.23456). The extended price (Quantity x Unit Price) must also have 5 decimal places if the unit cost has 5 decimal places. Basically if the user types in 2 for a Qty. and 1.23456 for a Unit cost, the Extended price must be 2.46912 and not 2.47. This would normally be easy: Code: Format(ExtendedCost, "0.00000") However, what if they enter 2 for a quantity and 2 for a unit cost. I want it to display 4.00 and not 4.00000.
Basically what I want to know is: How to get rid of trailing 0's? Would I have to use the Left or Right functions or is there a something similar to Trim but for 0's instead of whitespace...?
I hope that makes sense.
Thanks for any help,
Tom
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Remove Trailing White Space.
Hi Guys,
On a form I have a TextBox control, I use it to input a name and search a database- No probs there....
But I am a bit Lazy and like to copy and paste the names into this text box as its quicker....
But when I paste into my textbox I seem to get a trailing white space regardless of how carefully I copied the text into my clipboard memory..
Suggestions of a way to solve this would be gladly recieved.
I think I may have to use the Trim$ Function?? But how? and on what event?
Thanks again for any thoughts
Regards
Ld
Remove Trailing White Space
I'm sure this has been asked before but I can't find the answer.
I want to remove all the trailing white space from a string without reversing it and parsing it character by character, isn't there a VB function for this?
Trailing Frames
I blitted a character image to the screen, and can move it around, but it leaves a trail behind it. Anyone know how to fix this. this is what i have under my mainloop
Code:
Private Sub cmdStart_Click()
SpriteX = 1
SpriteY = 1
'Timer variables...
Dim T1 As Long, T2 As Long
'create a compatable DC for the back buffer..
myBackBuffer = CreateCompatibleDC(GetDC(0))
myBufferBMP = CreateCompatibleBitmap(GetDC(0), 6615, 5565)
SelectObject myBackBuffer, myBufferBMP
BitBlt myBackBuffer, 0, 0, 6615, 5565, 0, 0, 0, vbWhiteness
'load our sprite
mySprite = LoadGraphicDC(App.Path & "RIGHTPIC1.bmp")
mySpritemsk = LoadGraphicDC(App.Path & "RIGHTPIC1msk.bmp")
cmdStart.Enabled = False
'get current tickcount
T2 = GetTickCount
Do
DoEvents 'DoEvents makes sure that our mouse and keyboard dont freeze-up
T1 = GetTickCount
'if 20MS has gone by, execute our next frame
If (T1 - T2) >= 20 Then
CheckMovement
BitBlt myBackBuffer, SpriteX - 1, SpriteY - 1, _
32, 32, 0, 0, 0, vbBlackness
BitBlt myBackBuffer, SpriteX, SpriteY, 32, 32, mySprite, 0, 0, vbSrcAnd
BitBlt myBackBuffer, SpriteX, SpriteY, 32, 32, _
mySprite, 0, 0, vbSrcCopy
BitBlt Me.hdc, 0, 0, 6615, 5565, myBackBuffer, _
0, 0, vbSrcCopy
'update timer
T2 = GetTickCount
End If
'loop it until our sprite is off the screen...
Loop Until SpriteX >= Form1.ScaleWidth Or SpriteY >= Form1.ScaleHeight Or SpriteX < Form1.ScaleLeft Or SpriteY <= 0
End Sub
Also the loop won't stop when i run off the right side of the form and run off the bottom. I think i did the collision for it wrong. Any ideas
Trailing Blanks
i have a database program that has a bunch of fields that i set longer in the vis data manager than a person can enter.
the result is for example: item number set to a max of 15 characters being only 10 and 5 blank spaces.
how do i get rid of those blank spaces?
its only important in cases when i'm like:
msgboxVar = "This will add 2 copies of item number " & itemnum & ". Are you sure?"
if msgbox (msgboxvar,vbyesno,balls) = blah
you get the point
Trailing Spaces
how do I get rid of trailing spaces in a string?
"1234 "
thanks
Audit Trailing
can anyone give me tips on how to code audit trail feature in my form, vb frontend and access backend
Trailing Spaces
Hello,
I have a db field which is 30 char long. I want to use it & display it in a text box, but the trailing spaces are a problem.
How do I get rid of them.
Thanks,
T
Getting Rid Of Trailing Spaces....
Hello,
How do I get rid of trailing spaces in a string??
I have strings called strName and strSurname, which are populated by fields from a table.
The strName however has trailing spaces which I want to get rid of.
EG. I want to display the name & surname on a msgbox..
msgbox strname & " " & strSurname
the result must be something like.. "John Cooper" - without any spaces (except the one I specified) between the name & surname.
Thanks
VB5 Trailing Whitespace
Hi
I'm writing a text file using the print function. I have some text then I want to add 19 characters of whitespace after it to represent 2 blank fields of data before adding a CRLF, I have tried using the Spc function and using a blank string literal but it always puts the CRLF straight after the end of the text, ignoring the whitespace.
Is there anyway I can put the 19 char's of whitespace in before the CRLF without having to add an extra non-blank character?
Thanks
Dalyboy
Trimming Off Trailing TABS
Quick question... Trim() only gets rid of spaces. What's an easy way to get rid of trailing Tabs? I cant use replace() as that will get rid of Tabs I want to keep.
I hope I don't have to use Mid and work my way backwards..
Any other ideas?
Thanks
Removing Trailing Data
In my program using SQL i have to remove the proveeding and trailing data to leave just the e-mail address remaining (i.e the desired result being Joe.Bloggs@goodhope.nhs.uk) from the date given below
Code:
SMTP:Joe.Bloggs@goodhope.nhs.uk%X400:c=GB;a=NHS;p=NHS W MIDS HN;o=NHS GOOD HOPE HOSPITAL TR;s=Blogs;g=Joe;
i can remove the SMTP: bit from the front as shown below but how could i remove the redundant data after .nhs.uk bit from the data provided please baring in mind that the trailing bit changes and is never constant
Code:
'setup query to execute
strStandardiseMail = "UPDATE mail SET [mail].[E-mail Addresses] = Mid([mail].[E-mail Addresses],6,Len([mail].[E-mail Addresses])) WHERE [mail].[E-mail Addresses] LIKE 'SMTP:%'"
'Run command to remove SMTP: from e-mail addresses
cnn.Execute strStandardiseMail
cnn.Close
thx in advance
Peter
Getting Trailing Zeros With A Number
I have problem, that may have a very simple solution, but I can't quite get my head around it
I need to write data to a file in CSV format for an application, among other things a number with two digits after the point
This is easliy achieved by using the Format function, but the function returns a string variable, and the application requires it in number format (not enclosed in double quotes)
This is solved by converting the string to a number, using the Val function.
The problem is that when the digits after the point are zeros, it drops these zero's. So the question is, how to retain the trailing zeros after the point of a number (in number format)?
Unless I find a simple solution to this problem, might I have to write the number to the file byte by byte, and I'm really not looking forward to that
Any ideas will be appreciated
Pierre Myburgh (plm@wmeb.co.za)
Trailing Space Problem
Just wondered why, when double clicking on a work in a richtextbox, it always highlights the word and the following empty space.
Anybody know how to stop this.
I am making a find function, like in the edit menu
Getting Rid Of Leading And Trailing &"
If I input a file into a string using a simple Open (Path)for Input statement, The resulting string starts and ends with , e.g. h%*doih&*o*% . If I open the same file with a FileSystemObject type statement, the string starts and finishes with its first and last characters.
In the first instance, how can I rid the string of the s. The Replace(string,,) does not work for this situation.
ADO Chopping Off Leading And Trailing 0's
I'm reading a text file into a recordset, but when I look at the resulting data, many of the values are being concatenated, with the leading and trailing zeroes being chopped off. So, 02001.000 turns out to be 2001. These values are job #'s, so I need the zeroes there. I'm using access 2002, not sure if that's the problem, or if it's the way I'm interacting with the DB, or data types or what.
VB Code:
'create recordset Set cn = New ADODB.Connection Set cn2 = New ADODB.Connection cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & ";Extended Properties=Text;" cn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=po_fixer.mdb;Persist Security Info=False" sSQL = "SELECT * FROM detail.txt" Set rs2 = New ADODB.Recordset rs2.Open "SELECT * FROM detail", cn2, adOpenKeyset, adLockPessimistic, adCmdText If cn.State = adStateOpen Then Set rs = New ADODB.Recordset rs.Open sSQL, cn, adOpenKeyset, adLockOptimistic, adCmdText rs.MoveFirst MousePointer = vbHourglass Do While rs.EOF = False With rs2 .AddNew .Fields("linenum").Value = rs.Fields(0).Value .Fields("item").Value = rs.Fields(1).Value .Fields("qty").Value = rs.Fields(2).Value .Fields("brnloc").Value = rs.Fields(3).Value '<---chopping here .Fields("job").Value = rs.Fields(4).Value '<---chopping here .Fields("acct").Value = rs.Fields(5).Value .Fields("gross").Value = rs.Fields(6).Value .Fields("uom").Value = rs.Fields(7).Value .Fields("poid").Value = rs.Fields(8).Value .Update End With rs.MoveNext Loop
That's how I update the records. I checked the value of "job" after reading in the text file, and the zeroes are there, so it's somewhere in the above code, or just in Access itself where it's happening.
Any ideas?
Thanks in advance.
How Do I Get Rid Of Leading And Trailing Commas??
This the example I'm using, it formats to:
,N,N,N,E,E,W,
Need to remove the leading and trailing commas....
Dim strchars As String
strchars = "[11,11][N,N,N,E,E,W][10,01]"
Dim invals(0 To 11) As String
invals(0) = "["
invals(1) = "]"
invals(2) = "0"
invals(3) = "1"
invals(4) = "2"
invals(5) = "3"
invals(6) = "4"
invals(7) = "5"
invals(8) = "6"
invals(9) = "7"
invals(10) = "8"
invals(11) = "9"
For x = 0 To 11
strchars = Replace(strchars, invals(x), "")
Next x
MsgBox strchars
Thanks guys for you help this is an awesome site!
RobotGuy
Trailing Of User Forms? Weird..
Hey guys, i got a weird problem going on.... I have a bunch of user forms that prompt for user info when a spreadsheet is open. When it gets to like the 4th userform they start to leave a trail. (If you click on the form and drag it it leaves that infamous trail pattern). It used to work just fine, but once I started creating more user forms for a different section of this spreadsheet it started happening....Are there any limits to the vb code and maybe it just cant handle all the user forms or something? Or is there some common glitch that you can run into with wrong programming? THANKS!
Trim Trailing Line Breaks
Hi,
What is the best way to trim trailing line breaks (vbCrLf) from a string? Similar to RTrim to remove spaces. Do I have to loop and remove one by one?
Thanks,
Glenn
Rounding Cuts Off Trailing Zeroes
I need to round a double and put it into a textbox with 2 decimal places. I can round it, but it always cuts off trailing zeroes, like if the percent rounds to 27.00 then it would just show 27 or if it's 27.30 then it just shows 27.3. How can I always show 2 digits without a ton of if statements?
Any help would be appreciated, thanks!
Two Decimal Places Even With Trailing Zeroes
I am trying to make a program for a class. Part of it involves the user inputting currency values, and the amount of change is displayed. However, for the rest of the program to work, the change displayed HAS TO be formatted to exactly two decimal places, even if it ends in a zero (for instance, 3.70 has to display with the trailing zero, and NOT as 3.7 or the program will not function correctly.)
I have tried everything I can think of and have done searches all over the internet, but it still won't display right. I have tried using the regular Math.Round function, I have tried using the format function, I have tried converting it to a string, I have tried everything I can think of (I am still a beginner.) Please help! What can I do to make this work?!
MSFlexGrid Drops Trailing Zeros
I'm displaying numeric data from Access in a bound MSFlexGrid object and the trailing zeros are not displayed in the MSFlexGrid. In Access, the fields are set number or currency, fixed format, 2 decimal places, and in Access the full value always displays, e.g. "100.00". In MSFlexGrid, it comes out as "100". How to I get it to display the trailing zeroes in the same format that Access does?
Tom
Trailing Zeros Truncated -- HELP Mdac 2.7
I have been working on this problem all day. I think it' time to ask for help. I upgraded to MDAC 2.7 from MDAC 2.6 on a win 2000 machine and when retriving date from the SYBASE11 server the tailing zeros are truncated. ex 17,500 -> 175 I found Microsoft Knowledge Base Article - 237492 which is a fix for trailing zeros truncated with ado oledb provider for odbc but this infomation applies to odbc 2.0 and mdac 2.1 the workaround seem to work when I convert the Int field on my retrieve statement. But I would like to know what is causeing this problem.
Thanks in advance
PS When I install MDAC 2.6 everythin works fine.
Mysql - Trailing Spaces In Char Field
Using ADO.
I have a textbox bound to a field that is CHAR(255). When I retrieve the recordset (or refresh it), the field correctly displays the string specified.
However, if I ammend the field and update it, (record displays correctly after I update it), then move to a different record - then back to this record, the field is displayed padded with trailing spaces. Refreshing the recordset will make it display correctly.
I had the understanding that char fields eliminate the padding blanks when it's read. So I really don't understand why this is happening - the textbox itself has no code applied to it that would do this, so it's just the ADO recordset.
Any ideas on resolving this - I dont want to incorporate a refresh of the recordset, if a user retrieves 1 record the query will be quick, but if they retrieve (for instance) the entire recordset then there is a pointless overhead.
Crystal Reports Suppress Trailing Zeros
i m using crystal reports 8.5 and i m tryin to format numbers. the datatype in sql server is numeric and has a scale of 4. when i try to format a currency say 2.129, it becomes 2.1290; 2.19 becomes 2.1900 etc the trailing zeros keep showing up. is there anyway to suppress the trailing zeros? i cant specify a specific Decimal number in the Format Editor as the number of decimals can only be determined during run time. the only solution i haf found on the web regarding this is http://support.businessobjects.com/l...s/c2008521.asp
however wen i followed the link in the above web page to download the User Function Library file called UFLSTRNG.EXE, it does not exist. is there anyway to format the numbers not to display any trailing zeros without using the additional function called StringAfterChar that is contained in UFLSTRNG.exe?
the numbers i wanted to format ranges from either whole number to number with 4 decimal place. can someone please help?
Listbox - Trailing Comma For Multiple Records
I have the following code:
vb Code:
strSQL = strSQL & "WHERE MerchantID in (" For f = 0 To lstMerchants.ListCount - 1 If lstMerchants.Selected(f) Then strSQL = strSQL & (lstMerchants.ItemData(f)) & "," End If Next f strSQL = strSQL & ")"
At the moment, it lists merchants in a listbox and allows the user can select as many merchants as desired. It worked well in Access and there was no probs, but when trying against a SQL database the trailing comma throws the query. If the user selects one record, then no comma, and also shouldn't be a comma on the last selected merchant. I've tried SelCount but couldn't figure out the best way to use it.
I'm sure its simple but whats the best way to counteract this problem?
Thanks in advance!
Delete Trailing Empty Lines In RichTextBox
Ok if I have a richtextbox on my form which has the following text:
Quote:
hello
How can I turn it into:
Quote:
hello
without loosing the formattings?
Basically I need to delete all the trailing empty lines, but I'm not sure how. Please help!
Strange, RTrim() Can Not Strip Trailing Spaces
Very strange, RTrim() can not work in the following case:
Dim curPath As String * MAX_PATH
Dim s As String
Dim lngRet As Long
lngRet = GetCurrentDirectory(MAX_PATH, curPath)
s = RTrim(curPath)
The trailing spaces in curPath remains in s.
Who can tell me why? Thanks a lot.
Prevent Textbox From Removing Trailing Line Feeds
I'm having some troubles in retrieving the original value from a Textbox. I have a textbox control with the EnterKeyBehavior set to true, so that a user can use the Enter key to create line feeds in the text box.
Now this works fine, but my problem is that if a user types some text in the textbox and ends the text with some empty lines by hitting the Enter key a few times, these final Enter keys (or linefeeds) are NOT stored in the Textbox value while the line feeds ARE stored inbetween 'normal' text. So it looks like that, at the time the text from the textbox is stored under its '.Value' property the trailing linefeed characters are trimmed? However, I really need these trailing linefeeds. Is there a solution for this? Or is it just impossible using VBA?
Format Without Trailing &".0&"
When using the statement Format$(x,"00.0")
to get a number formatted to one D.P.
it will format (for whole numbers): xx.0
For this case, Is there a way to format without the
trailing ".0" ?
Why Can I Remove A User From A Group But I Can't Remove A User
HI thanks for looking at this post
I am able to programmatically remove a user and add a user and
set a password to anything i like in the System database from VB
but i can't find out how to delete a user completely does anyone
know how?
The following code will remove a user from a group
but not delete the User completely...
Code:
'---------------------------------------------------------------------------------------
' Procedure : DAORemoveUser
' DateTime : 14,Nov,2003 22:50
' Author : Steven Renoir
' Purpose :
'---------------------------------------------------------------------------------------
'
Public Sub DAORemoveUser(strUserName As String, strGroupName As String)
On Error GoTo DAORemoveUser_Error
Dim gName As String, _
U As User
Set U = DBEngine.Workspaces(0).Users(strUserName)
gName = U(strGroupName).Name
If gName = strGroupName Then
U.Groups.Delete strGroupName
Else
NoUserFound:
MsgBox strUserName & " does not exist in " & strGroupName
End If
Exit_DAORemoveUser:
Exit Sub
DAORemoveUser_Error:
If Err <> 3265 Then
MsgBox _
"Error " & Err.Number & " (" & Err.Description & ") has occured " _
& vbCrLf & "in the DAORemoveUser procedure of Module Security" _
& vbCrLf & " in the interests of making the program bug free" _
& vbCrLf & vbCrLf & " Please Email Software support at haus@upnaway.com" _
, vbExclamation, "Please Write Down This Error Message!"
WriteError Err.Number, Erl, Err.Description, "Security Module", "DAORemoveUser"
Else
Resume NoUserFound
End If
Resume Exit_DAORemoveUser
End Sub
This code is ADO but i am not sure how to use it
seeing as i am using DAO in my App
Code:
Private Function DeleteUser(ByVal strUser As String) As Boolean
Dim catDB As ADOX.Catalog
On Error GoTo DeleteUser
' Instantiate the Catalog object.
Set catDB = New ADOX.Catalog
With catDB
' Open Catalog object in current database.
.ActiveConnection = CurrentProject.Connection
' Delete strUser.
.Users.Delete strUser
End With
' Close Catalog object.
Set catDB = Nothing
DeleteUser = True
DeleteUser_Err:
Msgbox Err.Number & ":" & Err.Description
DeleteUser = False
End Function
Ah! here it is at last!!!
Code:
Public Sub DAODeteUser(StrUser As String, strGroup As String)
On Error GoTo DAODeteUser_Error
Set U = DBEngine.Workspaces(0).Users(StrUser)
DBEngine.Workspaces(0).Users.Delete StrUser
Exit_DAODeteUser:
Exit Sub
DAODeteUser_Error:
MsgBox _
"Error " & Err.Number & " (" & Err.Description & ") has occured " _
& vbCrLf & "in the DAODeteUser procedure of Module Security" _
& vbCrLf & " in the interests of making the program bug free" _
& vbCrLf & vbCrLf & " Please Email Software support at haus@upnaway.com" _
, vbExclamation, "Please Write Down This Error Message!"
WriteError Err.Number, Erl, Err.Description, "Security Module", "DAODeteUser"
Resume Exit_DAODeteUser
End Sub
with
respect
Steve
Edited by - binduau on 11/14/2003 4:14:07 PM
Why &"remove&" Method Can Not Remove Controls Added Using &"add&" Method?
I use "add" method to dynamically add some controls in the form, then I use "remove" method to remove them, but it doesn't work!
My code is like following.
Private WithEvents Command1 As CommandButton
Private Sub Command1_click()
' some codes to be executed when Command1 is clicked
End Sub
Private Sub AddControl()
Set Command1 = Controls.Add("VB.CommandButton", "Command1")
With Command1
.Visible = True
.Caption = "Command1"
.left = 2000
.top = 1000
.width = 500
.height = 200
End Sub
Private Sub RemoveControl()
Controls.Remove "Command1"
End Sub
When AddControl() is executed, a command button named "Command1" is added to the form. But when RemoveControl() is executed, there is error, and the
error message is "Run-time error '365': unable to unload
within this context". Why does this happen? Thanks.
Remove Row
Could someone help me solve a little problem I'm having. I have a form with a MSFlexGrid that the user can add info to one row at a time from a text box and 3 combo boxs. I would like to have a button allowing the user to clear a row if they make a mistake. What I have now keeps bring up an err saying that I can not RemoveItem a fixed row. This is what I've go so far. Thanks for any help.
Private Sub ClearLast_Click()
With grdSchedule
If .Rows <> 2 Then
.RemoveItem intRow
End If
End With
End Sub
Private Sub grdSchedule_Click()
intRow = grdSchedule.Row
End Sub
Remove Right 1
Well this one really has me stumped. I have a string of "C:New" and I basically want to remove the right "" to make it "C:New".
There's gotta be a simple way of doing this..?
Any ideas?
How To Remove
hi, how to remove special character such as enter in database using vb6 so that when I create filesytemObject is should not be included
thanks
Remove A Tab
This is another silly question, but I can't figure it out.. I am using a Tab control,, I had 3 tabs at one point, but now I only want 2, I don't see anywhere to remove a tab, it is the last one, so should be easy.. If I reset the tab index number, I get "Invalid Property Value".. I don't want this done in code, I found that, but set permanently in application... Thanks so much In case it matters it is SSTab control.
Remove
i have lines like in one textbox
askjn mncvh ihdmnvkh ABC fdjdkfmk mv fkj
v kjmlkvjlk ABC mnjdfhkjdf kjhdsjfh
kjdfakj adfk lkHTjlkaf lkjlkaf lkjlkadf lkjlkafl ABC
m nmn jk jlkj lkjlkpoudfv lkjlkjvkjllllllllllll ABC fgHTRElkgfi
LGK GKdfsgb kfdsglkjljsglkjlsg
i need to remove any words located after "ABC"
Remove XX/100 From CR
Hello
How to remove XX/100 from Crystal Report whern use TOWORDS(1000).
I want to write ONLY instead of XX/100
Please help me
Remove DSN
Hi
How to remove DSN using VB programme.Databse is in MS Acess
Manish
Remove The < And The >
Hello!
While formatting Text in a Richtextbox I do this:
Code:
With rtbAllg
.Visible = False
sPos = 0
Do
sPos = .Find("<", sPos + 1)
If sPos > 0 Then
ePos = .Find(">", sPos + 1)
If ePos > 0 Then
.SelStart = sPos
.SelLength = ePos - sPos + 1
.SelColor = vbBlue
.SelBold = True
sPos = ePos + 1
End If
End If
Loop Until sPos < 1
.Visible = True
End With
Works fine, but now:
Now I just want to remove the ugly control characters like this: < and this: >
Any Ideas?
Thanks in Advanced,
MyVar
Remove?
Is there a way to remove something like rep() replaces?
ie. part of a string etc
I'm trying to remove the Left(string, 1) bit of a string and I'm not sure how
Remove Pt2
How would I remove the LAST character in a string?
Remove Tab
hi,
i wanna read a file line by line and save it in a variable
and then i want to remove all tabs in front of that line, but i dont know how to remove tabs (vbTab)? who can help me?
Remove Help
VB Code:
for each lst in lstview.ListItems With lstView If .SelectedItem.Checked = True Then .ListItems.Remove(.SelectedItem.Index) End IfEnd WithNext
does the above remove all the checked rows in the listview if i assign it to a cmd and clicked it??
i tried but it does not.....so does anyone has any ideas on how to remove those checked records on a listview using a loop or anything at a click of a cmd button?
Remove
what is the function for removing all the spaces from a string??
|