credit and debit signs

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

credit and debit signs

Post by sal21 »

IN a line of txt file i get a string similar my_string = mid(....1,2ecc) (are amount )

example:

1.067,491 C

1.067,490 D

in this case i get only the number and not D or C

How to compose automaticlyy the my_string wirth + if the letter i C and - if the letter is D

need this final result:

-1.067,490
+1.067,491

note:
the position of letters are aleways in the position after the number.
i think if the letter is C peraphs the number string not need + if i make a numeric summ or subctraction, or not?

Hope understand me:-)

User avatar
jscher2000
2StarLounger
Posts: 148
Joined: 26 Dec 2010, 18:17

Re: credit and debit signs

Post by jscher2000 »

Personally, I like to use Split() to parse strings. Example:

Code: Select all

Dim strArray() As String, my_string As String
strArray = Split("1.067,491 D", " ")
If strArray(1) = "C" Then
    my_string = "+" & strArray(0)
Else
    my_string = "-" & strArray(0)
End If
MsgBox my_string

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: credit and debit signs

Post by sal21 »

jscher2000 wrote:Personally, I like to use Split() to parse strings. Example:

Code: Select all

Dim strArray() As String, my_string As String
strArray = Split("1.067,491 D", " ")
If strArray(1) = "C" Then
    my_string = "+" & strArray(0)
Else
    my_string = "-" & strArray(0)
End If
MsgBox my_string
Nice... it work perfect!
Tks. :thankyou: :clapping:

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: credit and debit signs

Post by sal21 »

jscher2000 wrote:Personally, I like to use Split() to parse strings. Example:

Code: Select all

Dim strArray() As String, my_string As String
strArray = Split("1.067,491 D", " ")
If strArray(1) = "C" Then
    my_string = "+" & strArray(0)
Else
    my_string = "-" & strArray(0)
End If
MsgBox my_string

About this question...

admit i ahev a series of line with - and + value i need to chek when the summ of each this value are Zero, how to check?


example:
line of text =- 30
line of text =- 30
line of text =+ 60
in this case the last line test if the algebric summ of line in top is zero then msgbox("operation tested")


in effetct i can have in text lines:

amount uno 30 d
amount due 30 d
...
tot of.... 60 c

i hope understand me:-)
Last edited by sal21 on 26 Mar 2011, 23:06, edited 1 time in total.

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: credit and debit signs

Post by HansV »

Do you want to add the values from all lines in the text file?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: credit and debit signs

Post by sal21 »

HansV wrote:Do you want to add the values from all lines in the text file?
no add...

i loop line by line a text file....

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: credit and debit signs

Post by HansV »

Declare a variable of type Currency:

Dim curRunningSum As Currency

When you begin, set it to 0:

curRunningSum = 0

Each time you read a line, add the value from that line:

curRunningSum = curRunningSum + CCur(MyString)

You can then test whether the running sum is 0:

If curRunningSum = 0 Then
...
End If
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: credit and debit signs

Post by sal21 »

HansV wrote:Declare a variable of type Currency:

Dim curRunningSum As Currency

When you begin, set it to 0:

curRunningSum = 0

Each time you read a line, add the value from that line:

curRunningSum = curRunningSum + CCur(MyString)

You can then test whether the running sum is 0:

If curRunningSum = 0 Then
...
End If
ONLY YOU!!!!!!!!!!!!! :thankyou: :clapping: