Solved

Searching string and replacement

Posted on 2011-09-22
11
160 Views
Last Modified: 2012-05-12
Hi experts,

Trying to check the first char of a string. If its aminus I want it stripped out, if one doesnt exist then I want it added.

Thanks.
If IsDBNull(FlxGridInvoiceInfo(remove_minus, 14)) = False And (FlxGridInvoiceInfo(remove_minus, 15) = "Stock Adj") Then

                                       if first char is a minus strip it out
                  

                    Else
place a minus before the value

                    End If


                End If

Open in new window

0
Comment
Question by:deanlee17
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 

Author Comment

by:deanlee17
ID: 36580772
These are the top few lines too...

Dim remove_minus As Integer
For remove_minus = 1 To FlxGridInvoiceInfo.Rows.Count - 1
0
 
LVL 40
ID: 36580893
I do not see the string in you code, but here is a way to do it, given a string called s.

s = (-CInt(s)).ToString
0
 

Author Comment

by:deanlee17
ID: 36580905
The string will be the value in the flexgrid as it looks through...

FlxGridInvoiceInfo(remove_minus, 14)
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 40
ID: 36581021
And how do you reference the value in the flexgrid? Sorry, flexgrid is not a standard control and I do not use it, so I cannot give you the exact syntax.

Maybe something similar to this:

grid.Cells(remove_minus,3).Value = (-CInt(grid.Cells(remove_minus ,3).Value)).ToString
0
 

Author Comment

by:deanlee17
ID: 36581027
Ok thanks. What is the common way to insert a value into a string?
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 36581254
If the value is already a String, simply assign it directly:

Dim s As String
s=value

If not, the following does the job for most types of values:

Dim s As String
s=value.ToString

If not, then the value might have another method to do that:

Dim s As String
s=value.<Other Method>
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36582141
>If its aminus I want it stripped out, if one doesnt exist then I want it added.

Generally speaking, you can use string functions

Dim str as String = "-123"

If str.StartsWith("-") Then
   Str.TrimStart("-")
Else
   Str = "-" & str
End If
0
 
LVL 40
ID: 36582423
Manipulating strings as suggested by CodeCruiser can lead to problems in some situations.

The format of a negative number, including the position of the -, can be changed in the configuration panel. Assuming - at the beginning can lead to problems. You could well end up with -123- instead of removing the -.

This is why, in my solutions, I convert to an Interger and then back to a String. The conversion will take care of any format set in the Control Panel.
0
 

Author Comment

by:deanlee17
ID: 36585518
Ok just trying both solutions to see what i get,

Code cruiser yours errored with....

MissingMemberException
Public member 'StartsWith' on type 'Single' not found.
0
 

Author Comment

by:deanlee17
ID: 36585661
So ive now tried..

Didnt error but when the msgbox displayed the value it had not trimmed off any minuses

Thans
If IsDBNull(FlxGridInvoiceInfo(remove_minus, 14)) = False And (FlxGridInvoiceInfo(remove_minus, 15) = "Stock Adj") Then

                  
                    If FlxGridInvoiceInfo(remove_minus, 14).ToString.StartsWith("-") Then
                        FlxGridInvoiceInfo(remove_minus, 14).ToString.TrimStart("-")

                        MsgBox(FlxGridInvoiceInfo(remove_minus, 14))
                       
                    Else

                        MsgBox("Something")



                    End If

Open in new window

0
 

Author Comment

by:deanlee17
ID: 36585829
Nailed it, see attached....
If IsDBNull(FlxGridInvoiceInfo(remove_minus, 14)) = False And (FlxGridInvoiceInfo(remove_minus, 15) = "Stock Adj") Then

                    Dim Thestring As String = FlxGridInvoiceInfo(remove_minus, 14)
                    Dim addminus As String = "-"

                    If Thestring.StartsWith("-") Then

                        Thestring = Replace(Thestring, "-", "")

                        FlxGridInvoiceInfo(remove_minus, 14) = Thestring

                 

                    Else

                        FlxGridInvoiceInfo(remove_minus, 14) = addminus & Thestring


                    End If


                End If

Open in new window

0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question