How can I take DocEntry from UDO form of SAP B1 in SDK? - sapb1

How can I take DocEntry from UDO form of SAP B1 in SDK?
I tried to take UDF, it works fine
Dim oForm As SAPbouiCOM.Form = SBO_Application.Forms.Item(SBO_Application.Forms.ActiveForm.UDFFormUID)
Dim oDocEntry As SAPbouiCOM.EditText = CType(oForm.Items.Item("U_Member").Specific, SAPbouiCOM.EditText)
Dim SelectedValueID As String = Convert.ToString(oDocEntry.Value)
Dim ID As Integer = SelectedValueID
But if I replace U_Member with DocEntry like this
Dim oForm As SAPbouiCOM.Form = SBO_Application.Forms.Item(SBO_Application.Forms.ActiveForm.UDFFormUID)
Dim oDocEntry As SAPbouiCOM.EditText = CType(oForm.Items.Item("DocEntry").Specific, SAPbouiCOM.EditText)
Dim SelectedValueID As String = Convert.ToString(oDocEntry.Value)
Dim ID As Integer = SelectedValueID
I get error message Add-on 9000012 failed with exception; Event Type:1
How can I solve this issue?
Please anyone can help me

You're trying to get the Item by the alias "DocEntry" - but there isn't an Item with that alias.
The UI elements don't generally use aliases which follow the database fields - they typically just numeric string identifiers e.g. "8" (which is the DocEntry EditText Item on Financial documents e.g. Orders, Invoices, etc).
If you want to check what the alias of the element is, turn on System Information (View => System Information, Ctrl+Shift+I) and mouse over the field. Look for the Item Alias in the bottom bar.

Related

Vb.NET Device Unique Identifier Win10

I'm trying to get a Device Unique Identifier in vb.net code. I have tried with
Private Function SystemSerialNumber() As String
Dim value As String = ""
Dim baseBoard As ManagementClass = New ManagementClass("Win32_BaseBoard")
Dim board As ManagementObjectCollection = baseBoard.GetInstances()
If board.Count > 0 Then
value = board(0)("SerialNumber")
If value.Length > 0 Then value = value.Substring(2)
End If
Return value
End Function
Which works on some computers but of the board doesn't have a serial number it returns "Default String" or whatever they put in there. Even tried with Win32_Processor and some have it and others just return "To be filled by O.E.M" lol
Also tried with,
Private Function SystemSerialNumber() As String
Dim value As String
Dim q As New SelectQuery("Win32_bios")
Dim search As New ManagementObjectSearcher(q)
Dim info As New ManagementObject
For Each info In search.Get
value = info("SerialNumber").ToString
Return value
Next
End Function
But its the same some devices have it some don't and just returns default string.
So I'm now trying is:
Private Function SystemSerialNumber() As String
Dim value As String
value = Windows.System.Profile.SystemIdentification.GetSystemIdForPublisher()
End Function
But I'm having trouble referencing to it. I tried Imports Windows.System but it just gives the error it cant be found.
As a side note I'm using this program in tablets with windows10, laptops, and desktops.
UPDATE: I'll be using as suggested by Heinzi. Thanks!
Also changed variable names to be more accurate.
Private Function NetworkAdapterMacAddress() As String
Dim McAddress As String
Dim netadapter As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim mo As ManagementObject
Dim adapter As ManagementObjectCollection = netadapter.GetInstances()
For Each mo In adapter
If mo.Item("IPEnabled") = True Then
McAddress = mo.Item("MacAddress").ToString()
Return McAddress
End If
Next
End Function
Well, there is no guaranteed ID that identifies every PC out there uniquely (fortunately, I might add. Privacy is a good thing).
You best bets are probably
the MAC of the network adapter (changes when the network adapter is replaced) or
the Windows Computer SID (changes when Windows is reinstalled).
Oh, and on a philosophical note, you might want to ponder on the Ship of Theseus.

How to delete a specific and not constant part of a string

I would like to cut this string
Dim str = "BMW{1}/X5{5}/image"
like this
Dim Brand = "BMW"
Dim idBrand= 1
Dim Model = "X5"
Dim Resource = "image"
for the / part I can easily do str.Split("/") but for the {1} I don't know if there is a special function or not.
This is a good place to use regular expressions:
Dim str = "BMW{1}/X5{5}/image"
Dim regex as new RegEx("(?<brand>[^{]+){(?<idbrand>\d+)}\/(?<model>[^{]+){[^}]+}\/(?<resource>.*)")
Dim match = regex.Match(str)
match is now an object containing various bits of information about what it's found. Since I added named capturing groups into the regex (brand, idbrand, model and resource), you can now access those within the match object:
Dim Brand = match.Groups("brand").Value
Dim idBrand= match.Groups("idbrand").Value
Dim Model = match.Groups("model").Value
Dim Resource = match.Groups("resource").Value
There is lots of information on regex available on the internet, one resource I find useful is regex101.com, which will give you an explanation of what the regex is doing on the right hand side.

Adding stuff to listview from textbox

id like to know how to take one of my text boxs or strings and put it in a listview.. well not really let me show u wants going on.
i have a 2 text box with the following stuff
TextBox1
cat123
hatcat
quanwall
samiam12
TextBox2
John
will
sam
dan
i want to take TextBox1's text and put it in one of the columns in the ListView. for example. ListView has 2 columns saying usernames and realnames, and TextBox1 is the usernames and TextBox2 is the realnames. So i want to take each line in TextBox1 to match up with the RealNames(TextBox2) all in ListView.
iv bin using the
Dim Q As New ListViewItem
Q.Text = Host
Q.SubItems.Add(User)
Q.SubItems.Add(Pass)
ListView1.Items.Add(Q)
to add the strings to the listview
I need this information ASAP, Thx u <3
Try this (To listview1 put your listview name)
Dim i As Integer = 0
For Each l In TextBox1.Lines
ListView1.Items.Add(l)
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(TextBox2.Lines(i))
i += 1
Next
i = 0
While the straightforward answer to your question is rather simple, your posted question raises issues. You are using Listbox and Listview interchangeably, yet they are two different controls. Moreover you seem to suggest your Textbox holds multiple values where the intention of a Textbox is to hold one distinct value or string of text.
As these controls are Windows Forms controls, your use of "Dim Q As New ListviewItem" may not be neccessary.
I would suggest reading up more on the controls you want to use, how they are used and in what context.
The simple straightforward answer to your question could be:
listBox1.Items.Add(textBox1.Text)
For reference: How to: Add and Remove Items with the Windows Forms ListView Control
I'm assuming your user names are stored in TextBox1 and your real names are stored in TextBox2
Public Sub AddListViewItemsFromTextboxes()
Dim Host As String = "SomeHost" 'you mentioned a host in the code snippet in your question, not sure where this comes from
Dim TextBox1String As String = TextBox1.Text
Dim TextBox2String As String = TextBox2.Text
Dim TextBox1Lines() As String = TextBox1String.Split(vbNewLine)
Dim TextBox2Lines() As String = TextBox2String.Split(vbNewLine)
If(TextBox1Lines.Count <> TextBox2Lines.Count)
'possible error handling here
MsgBox("Each user must have both a real name and a username.")
Exit Sub
End If
For NameIndex As Integer = 0 to (TextBox1Lines.Count - 1)
Dim UserName As String = TextBox1Lines(NameIndex)
Dim RealName As String = TextBox2Lines(NameIndex)
Dim Item As New ListViewItem
Item.Text = Host
Dim UserNameSubItem As New ListViewitem.ListViewSubItem
UserNameSubItem.Text = UserName
Item.SubItems.Add(UserNameSubItem)
Dim RealNameSubItem As New ListViewItem.ListViewSubItem
RealNameSubItem.Text = RealName
Item.SubItems.Add(RealNameSubItem)
ListView1.Items.Add(Item)
Next
End Sub
Example GUI:
http://i.stack.imgur.com/du95F.png
EDIT: Added third column

VB Import variable then use part 1 in dropdown and display part 2 to match selection in part 1

I'm using Visual studio to build a small utility.
I'm importing variables from a text file (this makes my program expandable in the future).
I'm running into a road block trying to split the variables into usable parts.
The text file is set up as such:
Game1:flshflhdlsfsdsfs
Game2:ugdjgndrgbdvdnjd
Game3:gnnereknengievke
And the code I've gathered from searching around trying to understand how I could do this is (It's gone through multiple rewrites but I feel this is probably the closest I've gotten):
Dim value As String = File.ReadAllText("Games.txt")
Dim cut_at As String = ":"
Dim x As Integer = InStr(value, cut_at)
Dim string_before As String = value.Substring(0, x - 2)
Dim string_after As String = value.Substring(x + cut_at.Length - 1)
Games_drp.Items.AddRange(string_before)
When I run a test like this, I get an error that String_before cannot be converted to an object. I tried switching "Dim string_before As String = value.Substring(0, x - 2)" to Dim string_before As Object = value.Substring(0, x - 2), but the dropdown that's supposed to be populated by at least one of the entries before the : has absolutely nothing in it.
Being pretty new at VB and feeling like I've exhausted pretty much every way I could think of searching in google and trying to piece together various bits of information, I figure I'd try asking my own direct question:
How would I go about reading all the lines from a text file, then splitting before the : to fill a combobox, and using a label to display the string after the : matching which ever entry is selected in the dropdown.
Thanks in advance for any help.
EDIT with full code:
Imports System.IO
Public Class Saves_frm
Private Sub Saves_frm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim value As String = File.ReadAllText("Games.txt")
Dim cut_at As String = ":"
Dim x As Integer = InStr(value, cut_at)
Dim string_before As String = value.Substring(0, x - 2)
Dim string_after As String = value.Substring(x + cut_at.Length - 1)
Games_drp.Items.AddRange(string_before)
End Sub
End Class
When run as is, I get an error that 'string_before' can't be converted from a string to an object, but when I make the following change from:
Dim string_before As String = value.Substring(0, x - 2)
to:
Dim string_before As Object = value.Substring(0, x - 2)
The error goes away, but the dropdown remains blank.
It's easier to use File.ReadAllLines, as it returns an array with all the file's lines. Then, you can loop through the lines, splitting each line and adding the result to the ListBox. This should be an example, but feel free to correct any mistakes I made, as I wrote it on my phone and it's been a long time since I used VB.
Dim lines() As String = File.ReadAllLines("file.txt")
For Each line As String In lines
Dim split() As String = line.Split(":"c)
gDic.Add(split(0), split(1))
Next
EDIT: Then, you most certainly want a dictionary that contains the name and the data, check the updated code.
Then, add the names by looping through gDic.Keys. When a name is selected, access its value with gDic("key").

How do you import a particular record in a database to your system and convert it to string for comparison?

Here's the deal, it's a log in form and I need to put case-sensitive validation, in other words if your Username = Admin then Admin != admin
Consider this code block (VB is really unfamiliar for me so break it to me gently ^^)
This is after it has matched a record in the database to the parameter passed to the function LogIn()
If dataTable.Rows.Count > 0 Then
'case-sensitive Validation follows
'data in Column ID and Password are placed in variables
'which are then compared to the arguments sent using the Compare() function
Dim strID = dataTable.Columns("U_ID").
Dim strPass = dataTable.Columns("Password")
Dim idResult As Integer 'both results will hold the value of String.Compare()
Dim passwordResult As Integer
*idResult = String.Compare(strID, ID)
the asterisk-ed line returns an error (obviously) as strId is not of data type String.
That's my dilemma.
I also tried using LIKE but again since strId and strPass are not Strings, all I get is an error.
Change this line:
Dim strID = dataTable.Columns("U_ID")
to this:
Dim strID as String = dataTable.Columns("U_ID").ToString