I’m trying to obtain data from a dll, but I do not know how to do it.
My code is:
'Function
Public Declare Function SET_XML_PATH Lib "EbmPapstFan.dll" (ByRef ruta As String) As Long
Public Declare Function GET_PRODUCTS Lib "EbmPapstFan.dll" (ByRef ruta As String) As Long
Sub Selec()
Dim ruta As String
Dim Int_A As Long, Int_B
ruta = "C:\ebmpapst\data\AC\"
Int_A = SET_XML_PATH(ruta) 'If Int_A=0 then they aren't mistake
Int_B = GET_PRODUCTS("")
Worksheets("Selec").Range("E2").Value = Int_B 'Nº products
End sub
Results are:
Int_A= 0
Int_B= 18
This isn't a mistake with the path because Int_A is 0. In addition, GET_PRODUCTS gives me the number of products that software has. The manual say that this function also has string character output.
The primary problem is that I don’t know how obtain this other string character output.
vb dll strange output in C#
Both outputs of the declared functions are "Long" and not "String" so there's no way that they're outputting anything except that.
I'd recommend revisiting the manual you refer to, to see exactly how it is documented and what the string value's function call would be.
The 2 function declaratons show long as the return types, however, the string being passed in is going in byRef and not byVal. It is possible that the string value is being returned via that parameter being adjusted inside the call.
More details about the documentation would be helpful.
Related
I am writing a Contains method for vb6 collections that hold strings.
However I cannot get the syntax right on my foreach.
What should I change?
Public Function Contains(col as Collection, key as Variant) as Boolean
Dim thing as Object '// this is the key
For Each thing in col
If CStr(key) = CStr(thing) then
Contains = True
Exit Function
End If
Next
Contains = False
End Function
I'm trying to read text from a file in SML. Eventually, I want a list of individual words; however, I'm struggling at how to convert between a TextIO.elem to a string. For example, if I write the following code it returns a TextIO.elem but I don't know how to convert it to a string so that I can concat it with another string
TextIO.input1 inStream
TextIO.elem is just a synonym for char, so you can use the str function to convert it to a string. But as I replied to elsewhere, I suggest using TextIO.inputAll to get a string right away.
Here is a function that takes an instream and delivers all (remaining) words in it:
val words = String.tokens Char.isSpace o TextIO.inputAll
The type of this function is TextIO.instream -> string list.
I have the following Extension Method
Imports System.Runtime.CompilerServices
Namespace Extensions
Public Module IntegerExtensions
<Extension()>
Public Function ToCommaDeliminatedNumber(ByVal int As Integer) As String
Dim _input As String = int.ToString
Select Case int
Case Is > 99999 : Return _input.Remove(_input.Length - 3) & "k"
Case Is > 9999 : Return Math.Round(Double.Parse(int / 1000), 1).ToString & "k"
Case Is > 999 : Return String.Format("{0:N0}", int)
Case Else : Return _input
End Select
End Function
End Module
End Namespace
And in one of my classes I'm using
user.Reputation.ToCommaDeliminatedNumber
I am importing the Extensions Namespace into the Class, but the error I'm getting is...
'ToCommaDeliminatedNumber' is not a member of 'Integer?'.
Can anybody tell me what I might be missing here? I do have other Extension Methods for Strings and Dates that work exactly as expected... I'm just at a loss on this one.
Judging from your error message it looks like user.Reputation is actually a Nullable(Of Integer), based on the trailing question mark ('Integer?'). Is that correct?
Your extension method is extending Integer, not Integer? (i.e., Nullable(Of Integer)), hence the error. So either provide an overload that handles Integer? or call Value on the nullable type:
user.Reputation.Value.ToCommaDeliminatedNumber()
You will need to check that it is not null (Nothing) otherwise an exception will be thrown. An overloaded method might look like this:
<Extension()>
Public Function ToCommaDeliminatedNumber(ByVal int As Integer?) As String
Return int.GetValueOrDefault().ToCommaDeliminatedNumber()
End Function
In the case that it's null the default value of 0 would be displayed.
I have the following code:
Public Shared Function GetAvailableManufacturers() As List(Of Manufacturer)
'first get all the live orders and extract their mfrs'
Dim sos As List(Of OrderForm) = GetFormsByStatus(StockStatus.Building)
Dim unavailableMfrs As New List(Of Manufacturer)
For Each so As StockingOrder In sos
unavailableMfrs.Add(so.Source)
Next
'then remove all mfrs with an open SO from a list of all mfrs'
Dim allMfrs As List(Of Manufacturer) = Manufacturer.GetManufacturers
Return allMfrs.Except(unavailableMfrs) <----- error here
End Function
Explanation of what the above does:
GetFormsByStatus() self-explanatory
GetManufacturers() returns a list of all manufacturers in the database
My idea to get available manufacturers was to get a list of all the manufacturers in my open forms, then get a list of all manufacturers and exclude all the manufacturers in the first list, illustrated like so (pseudo):
List A: {1,2,3,4,5,6,7,8,9,10}
List B: {5,7,10}
Result: {1,2,3,4,6,8,9}
I have set up my Manufacturer class according to this article so that it can be compared, but I'm still getting this error:
Unable to cast object of type '<ExceptIterator>d__92'1[csCore.Manufacturer]' to type 'System.Collections.Generic.List'1[csCore.Manufacturer]'.
I thought at first that because during testing GetFormsByStatus() returns 0 results maybe that was causing problems, but it doesn't make sense that Except() wouldn't work if the provided list had 0 items. Can anyone spot what I'm doing wrong?
Thanks so much!
The function expects a List(Of Manufacturer) return type, not an IEnumerable(Of Manufacturer), so adding a .ToList() to the return value should fix it:
Return allMfrs.Except(unavailableMfrs).ToList()
Your function is declared as returning List(Of Manufacturer), but your Return statement is returning only an IEnumerable(Of Manufacturer). Change the return statement to:
Return allMfrs.Except(unavailableMfrs).ToList()
If you turn Option Strict On, I believe VB will catch this kind of error at compile time, instead of blowing up at runtime.
The problem is that Enumerable.Except returns IEnumerable<T>, but your return type is List(Of T).
Change your last line to:
Return allMfrs.Except(unavailableMfrs).ToList()
Public ReadOnly Property IsAlphaNumeric(ByVal entry As String) As Boolean
Get
Return New Regex("(?!^[0-9]*$)(?!^[a-zα-ωA-ZΑ-Ω]*$)^([a-zα-ωA-ZΑ-Ω0-9]{6,15})$", RegexOptions.IgnoreCase).IsMatch(entry)
End Get
End Property
This one is pretty good for Greek and English language.
What about all the other languages in the universe?
Should i replace the above code with another function, validating keycode data and text length or what?
I would recommend to use unicode character definitions instead, such as \p{L} for letters and \p{N} for numbers.
You can find documentation on which categories that are recognized at MSDN.
However, I am not sure whether it supports the Klingon alphabet.
This one is brilliant also! Found at a1vbcode.com
Public Function IntlIsAlphaCharacter(sChar As String) As Boolean
IntlIsAlphaCharacter = (Not (UCase(sChar) = LCase(sChar))) Or (sChar = " ")
End Function
The native language of klingons is regex's?