|
it works..thanx so much... 
|
|
|
|
|
Happy to help.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
Hello,
I get the following error in run time.
Error message
Unable to cast from a number, the value must be less that infinity.
My code in vb .net visual studio 11
Form load
Me.Client = New DXProf(Me) --Excetion thrown here---
Me.components = New Container
Dim manager As New ComponentResourceManager(GetType(Form1))
DXFramework.m_Icon = DirectCast(manager.GetObject("$this.Icon"), Icon)
DXFramework.LoadInstance(Me.Client, Me)
End Sub
End Sub
Here is the exception detail.
System.InvalidCastException occurred
Message=Unable to cast object of type 'DXProf' to type 'idt.medical.IDXClient'.
Source=DXPro
StackTrace:
at DXPro.Form1.Form1_Load(Object sender, EventArgs e) in C:\VBDXDCURRENT\Functionional No Errors\DXPro\Form1.vb:line 73
InnerException:
Any help would be appreciated.
Michael
|
|
|
|
|
What the (explitive deleted) is "DXProf"?? It's surely not part of the .NET Framework, so it's VERY unlikely anyone is going to know about it.
If it's a third party lirbary, you're best bet for getting help on this problem would be the people who wrote that library.
|
|
|
|
|
Dave,
Thanks for your info,
I am the only one working on this program. The original author is not with us anymore and I a picking up the pieces. I have so so source code and comments and no documentation either.
DXProf is a component in the app that works with externel .dll's. I personally would not have written it that way. But I have deal with what I have.
Thanks for your help.
Michael
|
|
|
|
|
KireronThunderStone wrote: Message=Unable to cast object of type 'DXProf' to type 'idt.medical.IDXClient'.
This message tells you everything you need to know. You are trying to initialise a idt.medical.IDXClient object from a DXProf object, but the two are not compatible.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
|
From this, and your other responses, I get the feeling you do not really understand inheritance and still have no idea what this error is about. You need to look at your class definitions to see why the two are incompatible.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
|
In case that it was you (or someone of your colleagues) to develop that DXProf component, make sure that it inherits from 'idt.medical.IDXClient ' (which might be an interface).
Actually I'd expect the compiler to complain - is there still some kind of "Option Explicit Off" in that version of VB?
|
|
|
|
|
Bernhard,
Thanks for the info, I am the only one working on this project, the last developer and creator is no longer with us. I having to reconstruct everything with so so source code and no comments or documents to speak of.
In vb 2008 and version 11 there is a few choices of option explicit, so yes I could turn it off. There is also option strict which can be toggled off too.
Now you said to make sure that the DXProf component inherits from idt.medical.IDXClient. Could you give me an example. Yes you are right idt.medical.IDXClient is an interface.
Please help if you can.
And Thanks.
Michael
|
|
|
|
|
Get the source code of DXProf, and change the class statement:
Public Class DXProf
Implements idt.medical.IDXClient
Then you'll likely receive some error messages that DXProf must implement this or that function of property. Just do that. Take care of the exact signature of functions.
|
|
|
|
|
Here is the code i am using for this
Imports System
Imports System.IO
Imports System.Data.OleDb
Imports ADOX
Imports System.Data
Imports OLEDBError
Public Class Main
Private filename As String
Private TexttxtFileContents As String
Private paths() As String = Split(Environment.GetEnvironmentVariable("PATH"), ";")
Private Sub SplitContainer1_Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles SplitContainer1.Panel1.Paint
End Sub
Private Sub HTRADIO_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HTRADIO.CheckedChanged
HTGROUP.Visible = True
HTLTGB.Visible = False
End Sub
Private Sub HTANDLT_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HTANDLT.CheckedChanged
HTLTGB.Visible = True
End Sub
Private Sub HTCONButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HTCONButton.Click
Dim start_dir As String = System.Windows.Forms.Application.StartupPath
Try
With odlgTextFile
' See btnRetriveFileNames_Click for explanations of default values
' for the properties.
' Check to ensure that the selected file exists. Dialog box displays
' a warning otherwise.
.CheckFileExists = True
' Check to ensure that the selected path exists. Dialog box displays
' a warning otherwise.
'.CheckPathExists = True
' Get or set default extension. Doesn't include the leading ".".
.DefaultExt = "dbf"
' Return the file referenced by a link? If False, simply returns the selected link
' file. If True, returns the file linked to the LNK file.
'.DereferenceLinks = True
' Just as in VB6, use a set of pairs of filters, separated with "|". Each
' pair consists of a description|file spec. Use a "|" between pairs. No need to put a
' trailing "|". You can set the FilterIndex property as well, to select the default
' filter. The first filter is numbered 1 (not 0). The default is 1.
.Filter = _
"Database files (*.dbf)|*.dbf|All files|*.*"
.Multiselect = False
' Restore the original directory when done selecting
' a file? If False, the current directory changes
' to the directory in which you selected the file.
' Set this to True to put the current folder back
' where it was when you started.
' The default is False.
.RestoreDirectory = True
' Show the Help button and Read-Only checkbox?
.ShowHelp = True
.ShowReadOnly = False
' Start out with the read-only check box checked?
' This only make sense if ShowReadOnly is True.
.ReadOnlyChecked = False
.Title = "Select a file to open"
' Only accept valid Win32 file names?
.ValidateNames = True
If .ShowDialog = Windows.Forms.DialogResult.OK Then
Try
HTCONDTextBox.Text = .FileName
'Data Copy to GEC-Neplan Folder
Dim FileToCopy As String
Dim NewCopy As String
FileToCopy = .FileName
NewCopy = "C:\GEC-NEPLAN\HT-CONDCUTOR.DBF"
If System.IO.File.Exists(FileToCopy) = True Then
System.IO.File.Copy(FileToCopy, NewCopy)
End If
'HTCONDTextBox.Text = My.Computer.FileSystem.ReadAllText(.FileName)
Catch fileException As Exception
Throw fileException
End Try
End If
End With
Catch ex As Exception
'MsgBox(ex.Message, MsgBoxStyle.Exclamation, Me.Text)
End Try
End Sub
Private Sub HTPOLEButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HTPOLEButton.Click
Try
With odlgTextFile
' See btnRetriveFileNames_Click for explanations of default values
' for the properties.
' Check to ensure that the selected file exists. Dialog box displays
' a warning otherwise.
.CheckFileExists = True
' Check to ensure that the selected path exists. Dialog box displays
' a warning otherwise.
.CheckPathExists = True
' Get or set default extension. Doesn't include the leading ".".
.DefaultExt = "dbf"
' Return the file referenced by a link? If False, simply returns the selected link
' file. If True, returns the file linked to the LNK file.
.DereferenceLinks = True
' Just as in VB6, use a set of pairs of filters, separated with "|". Each
' pair consists of a description|file spec. Use a "|" between pairs. No need to put a
' trailing "|". You can set the FilterIndex property as well, to select the default
' filter. The first filter is numbered 1 (not 0). The default is 1.
.Filter = _
"Database files (*.dbf)|*.dbf|All files|*.*"
.Multiselect = False
' Restore the original directory when done selecting
' a file? If False, the current directory changes
' to the directory in which you selected the file.
' Set this to True to put the current folder back
' where it was when you started.
' The default is False.
.RestoreDirectory = True
' Show the Help button and Read-Only checkbox?
.ShowHelp = True
.ShowReadOnly = False
' Start out with the read-only check box checked?
' This only make sense if ShowReadOnly is True.
.ReadOnlyChecked = False
.Title = "Select a file to open"
' Only accept valid Win32 file names?
.ValidateNames = True
If .ShowDialog = Windows.Forms.DialogResult.OK Then
Try
HTPOLETextBox.Text = .FileName
'Data Copy to GEC-Neplan Folder
Dim FileToCopy As String
Dim NewCopy As String
FileToCopy = .FileName
NewCopy = "C:\GEC-NEPLAN\HT-POLES.DBF"
If System.IO.File.Exists(FileToCopy) = True Then
System.IO.File.Copy(FileToCopy, NewCopy)
End If
Catch fileException As Exception
Throw fileException
End Try
End If
End With
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, Me.Text)
End Try
End Sub
Private Sub NEXT1Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NEXTHCButton.Click
Call Link_Table("HTCON", "HT-CONDCUTOR")
End Sub
Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Check Wheter Folder Exists or Not;If Exists Delete and Creat New One
If (System.IO.Directory.Exists("C:\GEC-NEPLAN")) Then
System.IO.Directory.Delete("C:\GEC-NEPLAN", True)
End If
System.IO.Directory.CreateDirectory("C:\GEC-NEPLAN")
Dim cat As New Catalog()
Try
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\GEC-NEPLAN\SHAPE-NEPLAN.mdb")
'MessageBox.Show("Database Created.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch Excep As System.Runtime.InteropServices.COMException
MessageBox.Show(Excep.Message, "Error Database Not Created", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
cat = Nothing
End Try
End Sub
Public Sub Link_Table(ByVal filename As String, ByVal name As String)
'*****************************************************
'Creates a link in our database to the dbf 'filename'
'*****************************************************
'References:
'ADODB ( .Net:ADODB )
'ADOX ( COM:Microsoft ADO Ext 2.8 for DDL and Security )
Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
Dim con As New ADODB.Connection
'Copy long named files to allow an access connection
If Len(System.IO.Path.GetFileNameWithoutExtension(filename)) > 8 Then
System.IO.File.Copy(filename, System.IO.Path.GetDirectoryName(filename) & "\" & name & ".dbf", True)
filename = System.IO.Path.GetDirectoryName(filename) & "\" & name & ".dbf"
End If
'A connection to the database where you are adding the link
con.ConnectionString = "Data Source=""C:\GEC-NEPLAN\SHAPE-NEPLAN.mdb"";Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"
con.Open()
cat.ActiveConnection = con
'Get Rid of the old table if it exists
On Error Resume Next ' If the table is not there, ignore the resulting error
cat.Tables.Delete(name)
On Error GoTo 0
' Create the new table.
With tbl
.Name = name
.ParentCatalog = cat
' Set the properties to create the link.
.Properties("Jet OLEDB:Create Link").Value = True
.Properties("Jet OLEDB:Link Datasource").Value = System.IO.Path.GetDirectoryName(filename)
.Properties("Jet OLEDB:Link Provider String").Value = "Dbase IV"
.Properties("Jet OLEDB:Remote Table Name").Value = name
End With
' Append the table to the tables collection of the catalog.
cat.Tables.Append(tbl)
con.Close()
' Clean up.
cat = Nothing
End Sub
End Class
|
|
|
|
|
..and what is the problem with the code? Does it throw an exception? If yes, what does the exception say?
Bastard Programmer from Hell
|
|
|
|
|
It throwing an exception that:
in valid argument tb1
cat.Tables.Append(tbl)
while appending the table
|
|
|
|
|
Ah, you could have guessed that the error would be important. I haven't used DBaseIV in a few centuries, and I can't test your code; however, I guess that the table doesn't exist in the target-database.
Create the table by hand, run the code again. If it works, you'll need to write some code to create the table.
Bastard Programmer from Hell
|
|
|
|
|
I've googled, searched CodeProject, etc, and I hope I'm overlooking something, but here is what I want to do:
I want to call a Windows Form application from another Windows Form application.
The program being called, may be called from different form based applications and needs to know who is calling.
I've found in testing, that with this code, I can accept a parameter:
Public Shared Sub Main() <br />
If Command$() = "/CR" Then<br />
strAppStartedFrom = "CR" 'Started from Check Recon Application<br />
Else<br />
strAppStartedFrom = "--"<br />
End If<br />
MsgBox(strAppStartedFrom & Command$())<br />
frmFTP.ShowDialog()<br />
End Sub<br />
I've published it, and from what I can find it puts the exe in this location?
C:\Users\username\AppData\Local\Apps\2.0\0BTCBQ53.QL1\OMCV071R.O93\carr..tion_c302ad764aefaa28_0001.0001_bcaadc20b696e727\CarrollFlexFTP.exe /CR
This path seems like it might change and not be consistent when installing it for different users.
The above link works if it is executed with a /CR parameter, but I need a more stable way of doing this.
In the past I've pointed shortcuts to the setup.exe file in the location we publish the application to, but if I run the app using the setup.exe /CR parameter, it doesn't work.
Suggestions?
Lost in the vast sea of .NET
|
|
|
|
|
It appears that you're using ClickOnce deployment. If you want a more stable path, then you can't use ClickOnce Deployment. You have no control over the path that the app is installed to.
KreativeKai wrote: The above link works if it is executed with a /CR parameter, but I need a more
stable way of doing this.
What do you mean by this? Your code is just looking for a command line switch. It shouldn't care about the path that the thing was launched from.
KreativeKai wrote: In the past I've pointed shortcuts to the setup.exe file in the location we
publish the application to, but if I run the app using the setup.exe /CR
parameter, it doesn't work.
Why are you putting the /CR on the Setup.exe command line?? You didn't write Setup.exe and it won't pass on parameters, so what's the point here??
|
|
|
|
|
We are using clickonce deployment and yes, I agree this limits control. Setup.exe is not passing the parms, and like you said it basically shouldn't. The only exe that I have found to read the parms passed is when I use the random address they create on the fly.
Frustrating... The clickonce deployment gives you so many advantages but in turn takes the flexibility out of the process.
Oh well, I've already started coding the first app to call the second app, and I'll have to write and read a file to pass the information between the two and also keep the clickonce setup intact.
Thanks as always for your input...
Lost in the vast sea of .NET
|
|
|
|
|
KreativeKai wrote: The only exe that I have found to read the parms passed is when I use the
random address they create on the fly.
Why are you even concerned about the path ClickOnce uses at all?? Are you saying that you have two applications where one launches the second and passes command line args?? ClickOnce was not designed for that at all. It was designed for simpler, single applications only. I suggest you don't use it at all because your requirements have outgrown the capabilities of ClickOnce.
If you package your applications using traditional MSI installers, your apps get installed under Program Files and you control the names of the folders used under that.
BTW, Command$ is the old VB6 way of doing it. VB.NET uses something more standardized:
Public Sub Main(ByVal args() As String)
You get the command line arguments already parsed for you in an array of strings.
|
|
|
|
|
Thanks for the BTW about the VB6 code... I found it on google and didn't realize.
I agree, my requirements have outgrown the capabilities of ClickOnce...
You asked:
Why are you even concerned about the path ClickOnce uses at all??
Basically what I found was if I pass the /CR parm into the app using:
1) The long random ClickOnce path - It works
2) The shortcut ...appref-ms /CR - It doesn't work
3) Published path setup.exe /CR - It doesn't work, and you explained this earlier, which makes sense why it does not...
4) Published path appname.application /CR - It doesn't work, and is probably for the same reason that setup.exe doesn't work.
All four ways start the program, but only #1 recognizes the parm? This is where my confusion is.
I'm just confused as to if I get the command line code working, which way can I execute the application.... or maybe command line parameters are best used when the application is not click once, which is sort of what you mentioned in an earlier thread.
Thanks for all your help so far, and hopefully this will clarify my confusion.
Lost in the vast sea of .NET
|
|
|
|
|
You have to learn why things work in Windows as well as how.
1) It works because you told Windows where to find the .exe you want to launch.
2) Shortcuts do not pass parameters to the command lines they launch.
In order for you to just click Start -> Run and type your app name, hit Enter and it launches, you have to include the path to your .EXE file in the PATH environment variable. (This is something inherited from the old DOS days.) You can't do that from ClickOnce AFAIK. You have to do it using a traditional MSI installer.
Good Luck!
|
|
|
|
|
I enjoyed the "old DOS days" and still have several DOS manuals on my bookshelf that come in handy once in a while. My problem is that my job responsibilities are 90% COBOL code and mainframe programming and only 10% of the time I can code in Visual Studio. When I do get a chance to work in VB, it sometimes becomes more trial and error.
Thanks for your help and enjoy your weekend!
Lost in the vast sea of .NET
|
|
|
|
|
I am not sure if this helps you, but I did find a way to accept parameters when launching a clickonce application. I activated the app by creating a new process using the uri to to the *.application file appending my arguments in the query string.
I am using VB10, I don't know if it will be the same for you if you are using something different.
From My Project -> Publish (tab) -> Options (button) -> Manifests
"Block application from being activated via a URL" should be UNchecked
"Allow URL parameters to be passed to application" should be checked
After you publish like that you can launch the other app by url including a query string (http://MyDomain.com/MyFolder/MyApp.application?MyParamValueA=1&MyParamValueB=2):
When the application is launched this way the query string arguments will not appear with the regular command line arguments, but instead need to be pulled from .Net like this (make sure you add null checks):
System.AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData(0)
|
|
|
|
|
I have made a program that calls itself.
I must pass the command line to it, but the program must know in with state it is. (first call or the second on)
I think i found the ideal solution for this problem.
The global atom database!
<pre lang="vb">
Private sub main()
Nta = FndAtom("AdminRunStatus")
If Nta = 0 Then
Nta = SetAtom("AdminRunStatus")
'set the status for the second run
'do something for the first run (shell to myself)
call shell (App.Path & "\" & App.EXEName & " " & Command)
End If
Exit Sub
Else
Call DelAtom(Nta)
'second program and the command line
call shell(Second program & " " & Command)
'do something for the second run.
End sub
This my created wrapper for the atom database:
Option Explicit
Private Declare Function InitAtomTable Lib "kernel32" (ByVal nSize As Long) As Long
Private Declare Function AddAtom Lib "kernel32" Alias "AddAtomA" (ByVal lpString As String) As Integer
Private Declare Function DeleteAtom Lib "kernel32" (ByVal nAtom As Integer) As Integer
Private Declare Function FindAtom Lib "kernel32" Alias "FindAtomA" (ByVal lpString As String) As Integer
Private Declare Function GetAtomName Lib "kernel32" Alias "GetAtomNameA" (ByVal nAtom As Integer, ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal lpString As String) As Integer
Private Declare Function GlobalDeleteAtom Lib "kernel32" (ByVal nAtom As Integer) As Integer
Private Declare Function GlobalFindAtom Lib "kernel32" Alias "GlobalFindAtomA" (ByVal lpString As String) As Integer
Private Declare Function GlobalGetAtomName Lib "kernel32" Alias "GlobalGetAtomNameA" (ByVal nAtom As Integer, ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Function SetAtom(ByVal AtomStr As String) As Integer
SetAtom = GlobalAddAtom(AtomStr)
End Function
Public Function GetAtom(ByVal Atom As Integer) As String
Dim buFfer As String
Dim lRet As Long
buFfer = String(255, 0)
lRet = GlobalGetAtomName(Atom, buFfer, Len(buFfer))
If lRet > 0 Then
buFfer = Left$(buFfer, lRet)
GetAtom = buFfer
Else
GetAtom = vbNullString
End If
End Function
Public Function DelAtom(ByVal Atom As Integer) As Integer
DelAtom = GlobalDeleteAtom(Atom)
End Function
Public Function LocDelAtom(ByVal Atom As Integer) As Integer
LocDelAtom = DeleteAtom(Atom)
End Function
Public Function LocSetAtom(ByVal Atom As String) As Integer
LocSetAtom = AddAtom(Atom)
End Function
Public Function LocGetAtom(ByVal Atom As Integer) As String
Dim buFfer As String
Dim lRet As Long
buFfer = String(255, 0)
lRet = GetAtomName(Atom, buFfer, Len(buFfer))
If lRet > 0 Then
buFfer = Left$(buFfer, lRet)
LocGetAtom = buFfer
Else
LocGetAtom = vbNullString
End If
End Function
Public Function LocFndAtom(ByVal AtomStr As String) As Integer
LocFndAtom = FindAtom(AtomStr)
End Function
Public Function FndAtom(ByVal AtomStr As String) As Integer
FndAtom = GlobalFindAtom(AtomStr)
End Function
Public Function LocInitAtom(nSize As Long) As Long
LocInitAtom = InitAtomTable(nSize)
End Function
|
|
|
|
|