I have the following ABAP program.
The program splits a line of text by space and fills variables and an internal table itab.
How to read the internal table in a loop and display it's values.
REPORT z_test110.
DATA: str1 TYPE string,
str2 TYPE string,
str3 TYPE string,
itab TYPE TABLE OF string,
text TYPE string,
wa LIKE LINE OF itab.
text = `Where do you want to go today`.
SPLIT text AT space INTO: str1 str2 str3,
TABLE itab.
LOOP AT itab INTO wa.
WRITE:/ wa.
ENDLOOP.
hey i tried the program and you can use this code it works perfectly.
still feeling issues comment here!
Related
I need to understand why this does not work in MS Access:
UPDATE main_records
SET main_records.rece = Str(main_records.Nr) & "," & Str(main_records.Pag);
The intent is to populate the rece column (63 chars string) in all records of main_records with the contents of Nr and Pag (converted to string and concatenated).
It looks so easy but ...
"the contents of Nr and Pag (converted to string and concatenated)"
If that is what you intend to do, you are to use a string conversion function
examples is
CStr( expression ).
Dim InputString() As String
Dim i As Integer
InputString = Split(InputName, " ")
For i = 0 To UBound(InputString)
CurrentDb.Execute "INSERT INTO InventoryInputT(InputID) VALUES ('" & InputString(i) & "')"
Next i
Thus, an entry of
data1 data2 data3
In the textbox of the form resulted in a table input of
record1 data1
record2 data2
record3 data3
Which is desired. The scanner we purchased uses either a 'tab' delimiter or a 'return'... it can also use 'add jump line' but I don't know what that means and it seems to be similar to return (on the surface)
Is there any way I can alter my code to either:
1) use the tab function
- the issue here is if the data in the scanner is represented as: 'data1 [tab] data2 [tab] data3'
and then I upload that to the textbox, access seems to read the data as:
-input 'data1'
-execute [tab] (which means it navigates out of my textbox to whatever the next button is)
... because it has navigated out of the textbox it can no longer enter 'data2' in the textbox... as such I don't know if this can be solved
2) Can I use the return setup as it allows each data entry to have its own unique line in the textbox
- can I adjust my code so it sets each line of the textbox to a value of i and then runs through my execute code? Example:
data entered (as displayed in textbox)
data1
data2
data3
Get code to read it as:
data1 = line1 = i=0 - execute to table
data2 = line2 = i=1 - execute to table
data3 = line3 = i=2 - execute to table
or something along those lines?
The second parameter of the Split() function is called Delimiter. This can be set to a single space, multiple spaces (as in your example) or even a tab character (vbTab in VBA). It's very flexible.
I have an Access database which contains a main table and a reference table. I'm trying to change a column in the table based on if it contains values in an array (pulled from the reference table) so the logic is something like this
Compare the value of the array to see if its contained within a column of the main table
If it is contained in the main table column change the group column to the value in the array
I have the code below which simply compares the value in the array against the table and prints the value. Im getting the error "Type mismatch". Does anyone know how i can compare the records?
Set rstTableName = CurrentDb.OpenRecordset("MAIN_TABLE")
For Each vItem In MyArray
Do While Not rstTableName.EOF
If InStr(1, [rstTableName!NAME], vItem) Then
Debug.Print (rstTableName!NAME)
End If
rstTableName.MoveNext
Loop
Next
You should be able to do this with just an update query.
For example:
Main_Table contains these fields - ID (AutoNum) and FieldToChange (Text)
ReferenceTable contains these fields - ID (AutoNum), ALookUpValue (Text), ChangeTo (Text)
If the value held in ALookUpValue appears anywhere in FieldToChange then replace the field value with whatevers in ChangeTo.
So, if FieldToChange contains ABCDEFG, ALookUpValue contains A and ChangeTo contains 'blah blah' then ABCDEFG will update to say 'blah blah'
UPDATE MainTable INNER JOIN ReferenceTable ON MainTable.FieldToChange LIKE '*' & ReferenceTable.ALookUpValue & '*'
SET MainTable.FieldToChange = ReferenceTable.ChangeTo
Hope that's understandable - end of the day. :)
Edit - test on a copy of your database - it will update values!
Several things:
Instr() returns a number (specifically variant type of Long) which is the first position of the lookup value. You have it compared to a boolean (T/F). But in VBA this is still legal as False is zero value and True non-zero value. However, it is advised never to rely on the equivalent numeric values of these types.
Brackets should not be wrapped around your entire recordset item but only around the field name:
Check the array item types. How it is declared and populated may invoke a Type Mismatch error. You do not include how array, MyArray is initialized and defined. For your needs, you need either String or Variant type array.
Try the following adjustment:
Set rstTableName = CurrentDb.OpenRecordset("MAIN_TABLE")
For Each vItem In MyArray
Do While Not rstTableName.EOF
If InStr(1, rstTableName![NAME], vItem) > 0 Then
Debug.Print (rstTableName![NAME])
End If
rstTableName.MoveNext
Loop
Next vItem
Alternatively, use the Like operator
Set rstTableName = CurrentDb.OpenRecordset("MAIN_TABLE")
For Each vItem In MyArray
Do While Not rstTableName.EOF
If rstTableName![NAME] Like "*" & vItem & "*" Then
Debug.Print (rstTableName![NAME])
End If
rstTableName.MoveNext
Loop
Next vItem
Ive searched over and over the internet for my issue but I havent been able to find / word my searches correctly...
My issue here is that I have a Comma Separated value file in .txt format... simply put, its a bunch of data delimited by commas and text qualifier is separated with ""
For example:
"So and so","1234","Blah Blah", "Foo","Bar","","","",""
"foofoo","barbar","etc.."
Where ever there is a carriage return it signifies a new row and every comma separates a new column from another.
My next step is to go into VB.net and create an array using these values and having the commas serve as the delimeter and somehow making the array into a table where the text files' format matches the array (i hope im explaining myself correctly :/ )
After that array has been created, I need to select only certain parts of that array and store the value into a variable for later use....
Andthats where my trouble comes in... I cant seem to get the correct logic as to how to make the array and selecting the certain info out of it..
If any
You might perhaps give a more detailed problem description, but I gather you're looking for something like this:
Sub Main()
Dim fileOne As String = "a1,b1,c1,d1,e1,f1,g1" + Environment.NewLine + _
"a2,b2,c2,d2,e2,f2,g2"
Dim table As New List(Of List(Of String))
' Process the file
For Each line As String In fileOne.Split(Environment.NewLine)
Dim row As New List(Of String)
For Each value In line.Split(",")
row.Add(value)
Next
table.Add(row)
Next
' Search the "table" using LINQ (for example)
Dim v = From c In table _
Where c(2) = "c1"
Console.WriteLine("Rows containing 'c1' in the 3rd column:")
For Each x As List(Of String) In v
Console.WriteLine(x(0)) ' printing the 1st column only
Next
' *** EDIT: added this after clarification
' Fetch value in row 2, column 3 (remember that lists are zero-indexed)
Console.WriteLine("Value of (2, 3): " + table(1)(2))
End Sub
My sheet already has data. Unfortunately, later I realized that all the values in column E should be validated and changed as necessary by calling my own user-defined function and passing the values as the function parameter. For example, say I have the following data in column E:
E1: "This is a text in (E1)"
E2: "This is a text in (E2)"
...
E7000: "This is a text in (E7000)"
Now, I want every value in column E to be changed by a formula like this:
E1: = RemoveBrackets("This is a text in (E1)")
E2: = RemoveBrackets("This is a text in (E2)")
...
E7000: = RemoveBrackets("This is a text in (E7000)")
Supposing Excel supports Regex, my problem can be solved easily. but unfortunately Excel doesn't. Could someone propose possible solutions to my problem?
Thanks in advance
1) Insert a new column "F"
2) Copy column E into F
3) Write in E1
=RemoveBrackets(F1)
4) Drag the E1 value through E7000
5) Hide column F.
Edit 1
You can do it with several passes of the Find/Replace feature:
Select the Column E before each PASS.
PASS 1
Find: <"This is a text in>
Replace with: <RemoveBrackets("This is a text in>
PASS 2
Find: <)">
Replace with: <)")>
PASS 3
Find: <RemoveBrackets(>
Replace with: <=RemoveBrackets(>
Edit 2
VB Regex substitute string function can be used from Excel.
You may dowload a toolpack such as Morefunc which supports a REGEX.SUBSTITUTE udf, or you could do your own udf using THIS as guideline.
I am posting here the code from the second reference, just for link independence:
Public Function SearchNReplace1(Pattern1 As String, _
Pattern2 As String, Replacestring As String, _
TestString As String)
Dim reg As New RegExp
reg.IgnoreCase = True
reg.MultiLine = False
reg.Pattern = Pattern1
If reg.Test(TestString) Then
reg.Pattern = Pattern2
SearchNReplace1 = reg.Replace(TestString, ReplaceString)
Else
SearchNReplace1 = TestString
End If
End Function
Please read the full article, as you should turn on the Microsoft VBScript Regular Expressions 5.5 option in Excel first.
HTH
Similar to belisarius' method, but doesn't leave a trace:
Insert column F
Insert into F1 the value =RemoveBrackets(F1)
Copy down through F7000.
Copy column F
Right click cell E1, Paste Special, choose "Values".
Delete column F