How to compare a FieldGetText with a number? - lotus-notes

I have a field that it stores a currency data with the name pdcPrimasVAFVigor.
I can get the value with the FieldGetText method about NotesUIDocument like this:
strPrimasVaf = uidoc.Fieldgettext("pdcPrimasVAFVigor")
And then I check the value and the type:
Msgbox "strPrimasVaf: " + Typename(strPrimasVaf)
This messagebox retrievme:
strPrimasVaf: 122.00 € STRING
If I want to compare strPrimasVaf with any number but the comparision doens't work, then I have tried to convert the data but I always get the next error:
Type Mismatch in method CoerStrToNum...
But, what have I tried?
I have tried to convert the string value before to compare like this:
Dim intPrimasVaf As Integer
intPrimasVaf = CInt(strPrimasVaf) ' Error
Dim dblPrimasVaf As Double
dblPrimasVaf = CInt(strPrimasVaf) ' Error
Dim curPrimasVaf As Currency
curPrimasVaf = CInt(strPrimasVaf) ' Error
Include I have try to change the format like this:
Dim x As Variant
x = Format(strPrimasVaf, "General Number")
Any advice or solution within using FieldGetText?

My advice: work with the backend document object.
Add
Dim doc as Notesdocument
Dim dblPrimasVaf As Double
Set doc=uidoc.document
dblPrimasVaf=doc.pdcPrimasVAFVigor(0)
No conversion needed.

Remove the € from the string with something like:
strPrimasVaf = uidoc.Fieldgettext("pdcPrimasVAFVigor")
strPrimasVaf=cdbl(fulltrim(join(split(strPrimasVaf,"€"),"")))

Related

Convert Dropdownlist String Value to Date

I want to do a date comparison to check whether is the Before Period is bigger than After Periode
So far it has been working properly until the date range is a bit tricky
For example
The value is from a dropdownlist item
Before period is 21-10-2022
After period is 04-11-2022
It will trigger the error message I set if the before period is bigger than the period after
I have a code like this
If CDate(ddlPeriodeBefore.SelectedValue) <= CDate(ddlPeriodeBefore.SelectedValue) Then
'Does the job if the the before period is smaller than after period
Else
lblInfo.Text = "Period BEFORE Must Be SMALLER Than Period AFTER."
End If
Can anyone help me? it keeps saying "conversion from string to date is not valid"
I've tried datetime.parse, parse exact, cdate, convert.todatetime but nothing works so far, or maybe I used it the wrong way
Please help, thanks in advance
Tim Schmelter's suggestion is not wrong, but I did want to provide an alternative. Create a collection of Tuple, add the dates (both formatted string and native value) to the collection, then bind the control to the list.
Here is the alternative:
Dim dates As New List(Of Tuple(Of String, DateTime))()
Dim today = DateTime.Today
For daysSubtract = 90 To 0 Step -1
Dim dateToAdd = today.AddDays(-daysSubtract)
dates.Add(New Tuple(Of String, DateTime)(dateToAdd.ToString("dd-MM-yyyy"), dateToAdd))
Next
ddlPeriodeBefore.ValueMember = "Item1"
ddlPeriodeBefore.DisplayMember = "Item2"
ddlPeriodeBefore.DataSource = dates
ddlPeriodeAfter.ValueMember = "Item1"
ddlPeriodeAfter.DisplayMember = "Item2"
ddlPeriodeAfter.DataSource = dates
Now when you go to get the selected value, you can use a simpler conversion since the stored object is already a DateTime:
Dim beforePeriod = DirectCast(ddlPeriodeBefore.SelectedValue, DateTime)
Dim afterPeriod = DirectCast(ddlPeriodeAfter.SelectedValue, DateTime)
If (beforePeriod <= afterPeriod) Then
' ...
Else
lblInfo.Text = "Period BEFORE Must Be SMALLER Than Period AFTER."
End If
The advantage to this approach is that you do not have to refactor your code if the date formatting changes.
If DateTime.Parse works depends on your curren culture because you don't pass any. For me this works fine (but for you not):
Dim selectedValue1 = "21-10-2022"
Dim selectedValue2 = "04-11-2022"
Dim beforePeriod = Date.Parse(selectedValue1)
Dim afterPeriod = Date.Parse(selectedValue2)
So either you know the correct culture that you have used when you have created this string, then you can pass this as second parameter to Date.Parse, or you use ParseExact:
Dim beforePeriod = Date.ParseExact(selectedValue1, "dd-MM-yyyy", CultureInfo.InvariantCulture)
Dim afterPeriod = Date.ParseExact(selectedValue2, "dd-MM-yyyy", CultureInfo.InvariantCulture)
The culture is relevant because they can have different date separators and the order of the day-, month- and year-tokens are different.

Get string after second delimiter VB NET

I am trying to get the part of the string after the second /.
For instance if I have the string "25/S17/874"
I would like to get "874"
Thanks
you can split the string by "/" and the call back from the array.
Example:
Dim string_sample As String
Dim string_arr As String()
string_sample = "25/S17/874"
string_arr = string_sample.Split("/")
Dim string_Result As String
string_Result = string_arr(2)
MsgBox(string_Result)
the string_Result is "874"
Dim result As String = "25/S17/874".Split("/"c)(2)
Obviously, some validation, error trapping, etc might be required if the string content is prone to variation.

Set a value from a collection to a variable

I am trying to do some debugging and I have a collection I created from several different strings. What I would like to do is go back and set another variable equal to the second item in the collection. Is this possible? See a very simplified example below:
Dim TagForms As New Collection
Dim TagForm1 As String
Dim TagForm2 As String
Dim TagForm3 As String
Dim Test As String
TagForm1 = "Cat"
TagForm2 = "Dog"
TagForm3 = "Pig"
Set TagForms = New Collection
TagForms.Add TagForm1
TagForms.Add TagForm2
TagForms.Add TagForm3
Test = TagForms(2) 'This doesn't work
Set Test = TagForms(2) 'This also doesn't work
As the variable 'Test' is a string, the last code line 'Set Test = TagForms(2)' does not work.
The correct code line is 'Test = TagForms(2)'. This code returns 'Dog'

How do I search an online document for specific string and it's value?

Example, Online document: [removed link as no longer needed]
Which outputs:
Value1=1
Value2=5
The rest of this document would have random text to ignore.
I would like to search for Value1 and Value2, then output it's value [I need this to be expandable if I decide to add new information in the future]
[the output may be longer than one character, and might be text rather than a number]
Dim Value1Result as Integer = [value from online file] '1 in this case
Dim Value2Result as Integer = [value from online file] '5 in this case
Edit: Added logic to strip the version number. Very basic but as long as the format doesn't change it should work. You'll need to handle parsing to int, double, etc if you ever use "1.2" or whatever for a version.
If I understand your question correctly, you just need to download the file, store it in a local variable, and then do something with it. Comment if this is not the case and I will adjust.
I would do this by creating a WebClient, downloading the data, converting it to a string, and then operating on it. I did not add any headers - dropbox doesn't require it, but something to keep in mind for production... Small example below:
Dim bResult() As Byte
Dim sUrl As String = "https://dl.dropboxusercontent.com/s/bus2q71wsn9txuz/Test.txt?dl=0"
Using client As New WebClient
bResult = client.DownloadData(sUrl)
End Using
Dim retData As String = Encoding.UTF8.GetString(bResult)
Dim retList As List(Of String) = retData.Split(Environment.NewLine).ToList()
Dim sMin = retList(0).Split("=").Last()
Dim sNew = retList(1).Split("=").Last()

Filling BAPI import table parameter in EXCEL using VBA

I have a query for me which requires to clear. I am using excel 2003. the sheet contains 12 columns. I need to do export data from excel to SAP. Before exporting I need to check if the record is exist or not, if exist then delete and insert.
I have two BAPIs for this one is import table, which needs to be filled the parameters, after filling this table the BAPI searches for the relevant records.
The list will be displayed in a table. I need to search that table with values from excel then import one field value to excel.
I write this code but, it is not working the BAPI giving Error 0.
Public Function Import_Order() As Boolean
Dim oBAPIGetOrder As Object
Dim oBAPIVariant1 As Object
Dim oBAPIVariant2 As Object
Dim oBAPIVariant3 As Object
Dim oBAPIImpOrder As Variant
Dim oBAPIRet As Boolean
Dim oDoNothing As Variant
gBAPIPlanOrder = 0
Set oBAPIGetPlOrder = sBAPIControl.Add("PLANED_GET_DET_LIST") 'BAPI
Set oBAPIVariant1 = oBAPIGetPlOrder.exports.Item("SELECTIONCRITERIA") 'Internal table
Set oBAPIVariant2 = oBAPIGetPlOrder.Tables.Item("DETAILEDLIST") 'Table
oBAPIVariant1.Value("MATERIAL") = eMaterial
oBAPIVariant1.Value("PLANT") = ePlnPlant
lBAPIRet = oBAPIGetPlOrder.call
If lBAPIRet Then
'oBAPIImpOrder = oBAPIGetPlOrder.imports.Item("PLANNEDORDER_NUM")
a = oBAPIVariant2.Rows.Count
oBAPIImpOrder = oBAPIVariant2.Value("PLANNEDORDER_NUM")
Import_PlannedOrder = True
Else
oBAPIImpOrder = 0
Import_PlannedOrder = False
End If
End Function
Thanks in advance for any help...
please place the call function statement
lBAPIRet = oBAPIGetPlOrder.call
after directly the exports statement and before the tables and importstatements

Resources