0

フィールド内のいくつかの文字列を検索して計算を実行する必要があります。

たとえば、このフィールドは 100KSGD です。

K を取得し、100 の値を 1000 に掛ける必要があるため、100,000SGD が得られます。

次に、SGD を取得し、それを SGD から USD への外国為替レートで乗算する必要があります。それが私が得なければならない価値です。

Instr を使用して K を取得し、フィールドに他の文字列がなければ計算を実行できました。

そのための私のコードは次のとおりです。

    If InStr(1 , OEMTEST_String$ , HasString_K$, 5) > 0 Then
            Print "Searching for letter K in OEMTEST field..."
            MsgBox("Letter K is found in OEMTEST field!")
            Print "Converting OEMTEST field..."

        'Replace  All occurrences of K  
        tempPosition = InStr( 1, OEMTEST_String$, HasString_K$ )    
        If( ( Len( OEMTEST_String$ ) - Len( HasString_K$ ) ) + 1 = tempPosition ) Then 
            OEMnvar = Left( OEMTEST_String$, tempPosition - 1 )
            MsgBox "The number value in OEMTEST field is " & OEMnvar

            OEMnewvar = CDbl(OEMnvar) 'change nvar from string to double
            OEMupdatedVar = CDbl(OEMnewvar * 1000) 'multiply the value by 1000

            MsgBox "new value of OEMTEST is " & OEMupdatedvar 'check message box

            'replace the value and save the document
            Print "Saving converted value of OEMTEST field..."
            Call note.ReplaceItemValue("OEMTEST", OEMupdatedVar)
            Call note.Save(True, False) 

        End If
        Else
        Print "Letter K not found in OEMTEST field..."
    End If

必要な値を取得するにはどうすればよいですか? ネストされた Instr を実行するにはどうすればよいですか?

どうもありがとうございます!

4

2 に答える 2

0

これには多くの穴がありますが、主な手法はSplit( InputValue, "K")、数値と変換記号を取得するために呼び出すことです。

Option Public
Option Declare

Sub Initialize
'
' We make lots of mistakes, here. Among the more serious:
'
'   1. Assume 'K' is always present between the number and the conversion symbol.
'   2. Assume the conversion symbol never has 'K' in it.
'   3. No error checking
'   4. Hard-coded conversion rate.
'
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '

    Const K_SEP = "K"

    Dim strParseThis As String
    Dim varParts As Variant
    Dim dblValue As Double
    Dim dblRate List As Double

    ' Build your conversion table. (Here as a List or load from a database.)    
    dblRate("SGD") = 0.7500 ' made up value, of course.

    strParseThis = "100KSGD"

    varParts = Split( strParseThis, K_SEP )

'   Print {"} + Join( varParts, {", "} ) + {"}

    If UBound( varParts ) = 1 Then
        ' Now we have an array with "100" in the first element and "SGD" in the second
        dblValue = Cdbl( varParts(0) ) * 1000.00 * dblRate( varParts(1) )
        Print strParseThis + " converts to " + Format( dblValue, "#,##0.00" ) + " USD"

    Else
        Print strParseThis + " did not have a " + K_SEP

    End If

End Sub
于 2013-10-08T16:19:46.157 に答える
0
' havent tried in script this but how about something like this :


const K="K"
dim sStartVal as string
dim sMoneyBit as string
dim sCurrencyBit as string
dim dMoney as double
dim sNewMoney as double
dim sngRatio as single

sngRato = 0.666 ' whatever the ratio of SGD to USD is
sStartVal="100KSGD"
if instr(sStartVal,"K")>0 then
    ' we have a K - might be at the beginning though
     sMoneyBit=strleft(sStartVal, K) ' stleft and strright get the string to left of right of second param
     sCurrencyBit=strright(sStartVal,K) ' never used, but your logic should use this to get the right ratio ?
     dMoney = cdbl("0"+sMoneyBit) * 1000 ' here cos we found a K so multiply out. Leading extra zero just handles case where string starts with a K
     dNewMoney = dMoney * sngRatio
end if
' dNewMoney = answer, or zero if no K found
于 2013-09-23T16:56:30.930 に答える