|
Jamal Abdul Nasir wrote: this the code in the crystal report's formula
Would have been useful in the OP.
if you own the select change the select/proc to return a non null value
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Don't tell any one
Like car accidents, most hardware problems are due to driver error.
Samir R. Ibrahim
|
|
|
|
|
I'll try to explain my problem using an example.
I have 2 classes (Class1 and Class2). I would like to insert pointers to instances of Class1 in an array that represents a property of class 2
This is the code:
Public Class Class1
Dim ciao As String = "Hello world"
Sub showciao()
MsgBox(ciao)
End Sub
End Class
Public Class class2
Public classi() As Class1
'HERE I DEFINE A METHOD TO CREATE A POINTER TO AN ISTANCE OF CLASS1 AND TO PUT IT IN AN ARRAY
Sub putclass2to1(ByVal index As Integer, ByRef classe1scelta As Class1)
classi(index) = classe1scelta
End Sub
End Class
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim c1 As Class1 'declare one object of class1
Dim c2 As class2 'declare one object of class2
c2.putclass2to1(1, c1) 'call the method to put a pointer to c1 in a row of the vector of c2
c2.classi(1).showciao() ' call a metod of c1 using c2 in order to verify that the pointer works
End Sub
UNFORTUNATELY I get in correspondence of the privatesub this error "Object reference not set to an instance of an object."
Where Am I doing wrong? where is the mistake? Please help me!
Thank you in advance for your help.
End Class
|
|
|
|
|
nico2007 wrote: Dim c1 As Class1 'declare one object of class1
Dim c2 As class2 'declare one object of class2
You haven't created an object of these two classes. You just declared to variables that can HOLD an object of those types. You haven't actually created an instance of them yet.
|
|
|
|
|
I forgot to use the word New in my example but I used it in the code.
Dim c1 as new class1
dim c2 as new class2
or
dim c1= new class1
....
But I still get that error!
|
|
|
|
|
Copy and paste the ACTUAL code in use. Don't retype it or guess at it. You're going to miss something.
|
|
|
|
|
Your issue is that you never redim'd classi() as class1. so while in routine putclass2to1 you are trying to fill classi(index) when classi has been properly created...
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
nico2007 wrote: Public Class class2
Public classi() As Class1
'HERE I DEFINE A METHOD TO CREATE A POINTER TO AN ISTANCE OF CLASS1 AND TO PUT IT IN AN ARRAY
Sub putclass2to1(ByVal index As Integer, ByRef classe1scelta As Class1)
classi(index) = classe1scelta
End Sub
End Class
You need to initialize your classi() array I guess.
Regards: Didi
|
|
|
|
|
please let me know if somebody used this function and reply me how to used it in VB 6.0
|
|
|
|
|
Try the following code:
Public Function SignMsg(CertContext As Long) As Boolean
Dim SigParams As CRYPT_SIGN_MESSAGE_PARA
Dim MessageArray(0 To 0) As String
Dim MessageSizeArray(0 To 0) As Long
Dim cbSignedMessageBlob As Long
Dim pbSignedMessageBlob As String
Dim GLE As Long
Dim rtn As Boolean
Const szOID_RSA_ENCRYPT = "1.2.840.113549.3"
Const szOID_OIWSEC_sha1 = "1.3.14.3.2.26"
On Error GoTo erh
SigParams.dwMsgEncodingType = PKCS_7_ASN_ENCODING
SigParams.pSigningCert = CertContext
SigParams.HashAlgorithm.pszObjId = szOID_OIWSEC_sha1
SigParams.HashAlgorithm.Parameters = 0
SigParams.cMsgCert = 1
SigParams.rgpMsgCert = CertContext
SigParams.cAuthAttr = 0
SigParams.dwInnerContentType = 0
SigParams.cMsgCrl = 0
SigParams.cUnauthAttr = 0
SigParams.dwFlags = 0
SigParams.pvHashAuxInfo = 0
SigParams.rgAuthAttr = 0
SigParams.cbSize = Len(SigParams)
MessageArray(0) = "A message" + vbNullChar
MessageSizeArray(0) = Len(MessageArray(0))
rtn = CryptSignMessage(VarPtr(SigParams), _
False, _
1, _
MessageArray, _
MessageSizeArray, _
0, _
VarPtr(cbSignedMessageBlob) _
)
GLE = GetLastError
If rtn = False Then
err.Raise 4021, , "Failed to retrieve signed blob size: " & GLE
End If
pbSignedMessageBlob = String(cbSignedMessageBlob, vbNullChar)
rtn = CryptSignMessage(VarPtr(SigParams), _
False, _
1, _
MessageArray, _
MessageSizeArray, _
VarPtr(pbSignedMessageBlob), _
VarPtr(cbSignedMessageBlob) _
)
GLE = GetLastError
If rtn = False Then
err.Raise 4022, , "Failed to sign message blob: " & GLE
End If
SignMsg = True
Exit Function
erh:
SignMsg = False
End Function
Requires a good certificate context passed in, plus:
Private Declare Function CryptSignMessage Lib "Crypt32" ( _
ByVal pSignPara As Long, _
ByVal fDetachedSignature As Boolean, _
ByVal cToBeSigned As Long, _
ByRef rgpbToBeSigned() As String, _
ByRef rgcbToBeSigned() As Long, _
ByVal pbSignedBlob As Long, _
ByVal pcbSignedBlob As Long _
) As Boolean
|
|
|
|
|
Hi, Could you please share the CRYPT_SIGN_MESSAGE_PARA stru in VB6? I need it tu use the CryptSignMessage function...
Thanks.
Diego.
|
|
|
|
|
I've got a couple of .bas files containing global constants, structures and function declarations. I want to use them in VB.Net(actually in C# ). How do I do that. Apologies if i havent posted this in the right forum. Thank you very much.
|
|
|
|
|
If you want to use them in C#, you'll have to rewrite the file. Or you can try one of the online VB.NET to C# code conversion utilities. All you have to do is Google for "VB.NET C# Conversion".
|
|
|
|
|
.bas?
You mean VBA code files? Can you be more specific?
|
|
|
|
|
the file is xxx.bas (a VB6 file ) containing global constants, function declarations and structures.
|
|
|
|
|
Ah, well you can't use old vb6 files in a .net application if I remember correctly. You're going to have to pick up vb.net syntax and grammer and port over your code.
|
|
|
|
|
you have to use the upgrading wizzard to convert the VB6 project to VB.NET and it will convert your .bas files to modules in VB.NET. When you are able to run your app under VB.NET you can convert it to C#. But why would you want to do that, you can have mixed languages in a solution.
Regards: Didi
|
|
|
|
|
They are only 2 *.bas files containing constants, structures and function declarations. Actually they are APIs (an old one), that asks me to add these two files in your vb6 project, in order to declare structure variables and call functions in it. But now i'm using .net. I'm looking if i can find any sample *.vbp file. Then i'll take your advice to upgrade it. With that i might get these 2*.bas files as 2 *.vb files. This would help me.
|
|
|
|
|
I thought, that you have a project, were the .bas files are part of it, then it would make sense to use the upgrade wizzard. If you only have to convert those files alone, and they are not too much code, I would try to copy paste the code into VB.NET and fix the errors, that are reported. That is probably faster.
Regards: Didi
|
|
|
|
|
I have finally created a .vbp file(looong story), added the two *.bas files in it, and upgraded it in VS2008. My
*.bas files were converted to *.vb files( ). But I got about 188 tasks to TODOs. After viewing them all I
found that there were only two types of warnings:
1.Fixed-length string size must fit in the buffer.
2.Structure may require marshaling attributes to be passed as
an argument in this Declare statement.
The first type of warning was fixed automatically during upgrade. The second type of warning was not
handled automaticaly.
So, to explain my question kindly see the details below:
The old VB6 code looks like this:
Type Struct1
str1 As String * 120
str2 As String * 120
str3 As String * 1024
End Type
\n
Declare Function MyFunction Lib "lib1.DLL" (pObject As Struct1) As Long
After upgrading VB.Net code looks like this:
Structure Struct1
'UPGRADE_WARNING: Fixed-Length string must fit in the buffer.
<VBFixedString(120),System.Runtime.InteropServices.MarshalAs(
System.Runtime.InteropServices.UnmanagedType.ByValArray,
SizeConst:=120)>
Public str1() As Char
\n
'UPGRADE_WARNING: Fixed-Length string must fit in the buffer.
<VBFixedString(120),System.Runtime.InteropServices.MarshalAs(
System.Runtime.InteropServices.UnmanagedType.ByValArray,
SizeConst:=120)>
Public str2() As Char
\n
'UPGRADE_WARNING: Fixed-Length string must fit in the buffer.
<VBFixedString(120),System.Runtime.InteropServices.MarshalAs(
System.Runtime.InteropServices.UnmanagedType.ByValArray,
SizeConst:=1024)>
Public str3() As Char
End Structure
\n
'UPGRADE_WARNING: Structure Struct1 may require marshalling attributes to be passed
as an argument in this Declare statement.
Declare Function MyFuntion Lib "lib1.DLL" (ByRef pObject As Struct1) As Integer
So after reading the second warning my marshall attribute turns out to be like this:
<br />
<StructureLayout(LayoutKind.Sequential, CharSet:=CharSet.ANSI)><br />
Structure Struct1<br />
...<br />
End Structure<br />
My question is that:
Is the attribute written correctly for the structure?
Do I have to write this manually for all other structures?
Do I have to use this in the Declare statement as well? How?
Thanks a dozen Didi.
|
|
|
|
|
There is a difference between warnings and errors. Warnings are for you to know, that tere can be a potential problem, or to teach you someting, but errors occure when something goes wrong. So, I did not try actualy, but this should compile and run ok, because it has only warnings...
Good luck: Didi
|
|
|
|
|
Thanks a lot for the reply. Well this is the last issue and after that
I am done. I got 3 errors, and they were of the same type.
'UPGRADE_ISSUE: Declaring a parameter 'As Any' is not suported.
Declare Function MyFunction2 Lib "myLib2" (ByVal arg As Any)<br />
As Integer
So can I use ByVal arg As Object instead of 'Any'?
Thanks again.
|
|
|
|
|
You should try to find out, what type the argument should be. See here[^] for reference. Good luck: Didi
|
|
|
|
|
I've got answers for everything(for now... ). Thanks a lot
|
|
|
|
|
I have an application written (VB6) a while ago and periodically updated. I keep old versions around simply by making a copy of the application source in a backup directory.
If I open the most recent version I find an error, Invalid use of Null (I know all about Nulls so lets not go down that path. Probably should have handled it better when it was originally written but when it was written we would not have had them, now we could)
If I open an older version of the program and run it, it does not give an error. This portion of code was last updated in 2003 or something and has not changed.
the offending line is
If UCase(rs!bin2File) = "CALLEDFROMDIAG" Then
in one version of code I get an error (current version), in the other (approx 6 months old) I do not
I know how to deal with it but am curious as to why it would behave differently...
any ideas?
|
|
|
|