|
If you create a form, you can get the window handle from it, it's a property.
Isn't Nothing the same as null ? If not, then just pass 0, a pointer with a value of 0 is null in C++.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks Christian,
I will try passing 0 as an integer value where I need a null sent to the C++ dll.
For the handle to the "progress form" I take it that i would create a form in VB.Net and pass it's handle to the file open as shown.
Regards
|
|
|
|
|
Reanalyse wrote:
For the handle to the "progress form" I take it that i would create a form in VB.Net and pass it's handle to the file open as shown.
I'd assume they need the form to have a progress bar on it with a specific ID, so that it can use it to update it's progress. I'd also hope you could pass null ( IntPtr.Null probably exists for this purpose ), and not have a progress dialog at all.
It's IntPtr.Zero ( I just checked ), so I'd try passing that rather than a straight 0, where Null is concerned.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks Christian
I have got a long way down the track thanks to your help
I have got this far
Am I passing the correct way to a VC++ DLL from VB.NET ?
------------------------------------------------------------------------------
Structure PVIEW
'// View Structure **********************************************
'typedef struct tag_VIEW
'{
'BOOL Viewable; // TRUE = Drawing can be viewed
'int WindowLeft; // Drawing Window Boundary Properties (In Pixels)
'int WindowTop; // Drawing Window Boundary Properties (In Pixels)
'int WindowRight; // Drawing Window Boundary Properties (In Pixels)
'int WindowBottom; // Drawing Window Boundary Properties (In Pixels)
'double ViewLeft; // Drawing View Properties (In Units)
'double ViewBottom; // Drawing View Properties (In Units)
'double ViewRight; // Drawing View Properties (In Units)
'double ViewTop; // Drawing View Properties (In Units)
'double PPU; // Pixels Per Unit
'double ZoomLevel; // Zoom Level
'} VIEW, *PVIEW;
Public Viewable As Boolean
Public WindowLeft As Integer
Public WindowTop As Integer
Public WindowRight As Integer
Public WindowBottom As Integer
Public ViewLeft As Double
Public ViewBottom As Double
Public ViewRight As Double
Public ViewTop As Double
Public PPU As Double
Public ZoomLevel As Double
End Structure
Public Class Form1
Inherits System.Windows.Forms.Form
Public Declare Function drwCreate Lib "CADIO" () As Long
'Exported Function drwCreate
'BOOL Create( );
Private Declare Function drwLoadDataFromFile Lib "CADIO" (ByVal Handle As Long, ByVal Handle1 As Long, ByVal Res0 As Integer, ByVal Filename As String, ByVal Handle2 As Long) As Boolean
'Exported Function drwLoadDataFromFile
'BOOL (*drwLoadDataFromFile)( HDRAWING hDrawing, OBJHANDLE BlockObjhandle, DWORD Reserved, LPCTSTR strFileName, HWND hWndProgress );
Public Declare Function drwInitView Lib "CADIO" (ByVal Handle As Long, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal Nheight As Integer) As Boolean
'Exported Function form DLL =drwInitView
'Public BOOL InitView( int x, int y, int nWidth, int nHeight );
Private Declare Function drwPaint Lib "CADIO" (ByVal drwhandle As Long) As Boolean
Private Declare Function dxfSetCurrentColor Lib "CADIO" (ByVal drwhandle As Long, ByVal Color As Integer) As Boolean
Private Declare Function drwGetViewProperties Lib "CADIO" (ByVal drwhandle As Long, ByVal Thisview As PVIEW) As Boolean
Private Declare Function drwAddBlock Lib "CADIO" (ByVal drwhandle As Long) As Boolean
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(128, 72)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim drwhandle1 As Long
Dim Blockhandle As Long
Dim RetVal As Boolean
Dim CurrentView As PVIEW
drwhandle1 = drwCreate()
RetVal = drwInitView(drwhandle1, 1, 1, 300, 300) 'returns true
RetVal = dxfSetCurrentColor(drwhandle1, 1) 'returns true
RetVal = drwPaint(drwhandle1) 'returns true
RetVal = drwAddBlock(drwhandle1) 'returns true
'Here is where trouble occurs
RetVal = drwGetViewProperties(drwhandle1, CurrentView) 'Does not work
RetVal = drwLoadDataFromFile(drwhandle1, Nothing, 0, "H:\test.dxf", Nothing) 'does not work
____________________________________________________________________________
The last two calls did not work at all
Regards
|
|
|
|
|
A BOOL is in fact a typedef for an int, pass 0 for false, 1 for true. It's used in APIs that are to be called from C, as C does not have a boolean type.
Are you declaring your handles as IntPtr ( can you access that type in VB.NET ) ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Changed both of those (you can use IntPtr in VB.Net but ")" as boolean came as a surprise ),the code previously still will not work with the changes.
Thanks
|
|
|
|
|
Reanalyse wrote:
boolean came as a surprise
Yeah, it's definately a trap.
Reanalyse wrote:
the code previously still will not work with the changes.
To be honest, anything else I suggest will just be a stab in the dark. If it were me, I'd be trying to use the dll in C++, then if I got that to work successfully, I'd be trying to move it to VB.NET. If it was usable in C++ and hard to use in VB.NET, I'd wrap it in a C++ COM project, and call that from VB.NET.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
i have written an App config file for my SQL server application containing the connection string. Im not sure if i have written the right code to read the connectionstring because when i run my app it says "ConnectionString is not initialized". Does anyone have any words of wisdom for my situation?????? If you do i will consider you the smartest person ever!
|
|
|
|
|
Hi Joey,
I just went through this myself.
Be sure you do this....
1. Be sure you have the ADODB component in your project
From VB menu.....Project - Components - Microsoft ADO Data Contro 6.0 (OLEDB)
2. Be sure you put the ADODB component on your form.
Example: Adodc1
3. Establish the database connection.....mine was to a SQL Server via ip
I put this in General-Declarations
Dim db As New ADODB.Connection
Const dbConnectString = "Provider=sqloledb;" & _
"Network Library=DBMSSOCN;" & _
"Data Source=xxx.xx.xx.xx,1433;" & _
"Initial Catalog=my_db_name;" & _
"User ID=my_user_ID;" & _
"Password=my_password"
4 Make the database connection in your code
db.Open dbConnectString
curID="1"
mySQL = "SELECT * FROM customer WHERE ID=" & curID& ";"
Set rs = db.Execute(mySQL _queID)
CompanyName = rs("CompanyName")
rs.Close
db.Close
set rs=nothing
set db=nothing
HTH
---- Mike
|
|
|
|
|
I created my connections with code also but what i am trying to figure out is why my code is not reading the connection string from the app.config file like it should. Here is some of my code.... Remember i have written an app config file and i am trying to get the code to read the connection string so when i install it on other machines i can just change the connection string in the config file. Some stuff i have 'ed , just disreguard those lines of code, they are the ones i was using before i started to work with the app.config.
this is my app config code:
<configuration>
<appsettings>
<add key="connstring" value="workstation id=JOEYP;packet size=4096;integrated security=SSPI;data source=JOEYP;persist security info=False;initial catalog=Tithe Master">
<add key="conn" value="workstation id=JOEYP;packet size=4096;integrated security=SSPI;data source=JOEYP;persist security info=False;initial catalog=Tithe Master">
HERE IS MY VB CODE:
Imports System.Configuration
...
Sub LoadData()
ListView1.Items.Clear()
'Dim conn As New SqlClient.SqlConnection("workstation id=JOEYP;packet size=4096;integrated security=SSPI;data source=JOEYP;persist security info=False;initial catalog=Tithe Master")
'Dim conn As New SqlClient.SqlConnection(conn1)
Dim Conn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("conn"))
Try
Conn.Open()
Dim adapter As New SqlClient.SqlDataAdapter
Dim cmd As New SqlClient.SqlCommand("SELECT * FROM tblTithes", conn)
adapter.SelectCommand = cmd
Dim reader As SqlClient.SqlDataReader
reader = adapter.SelectCommand.ExecuteReader
Dim itm As ListViewItem
While reader.Read
itm = New ListViewItem(Format(reader("ServiceDate").ToString, "Short Date"))
itm.SubItems.Add(reader("MemberID").ToString)
itm.SubItems.Add(reader("Tithes").ToString)
itm.SubItems.Add(reader("Missions").ToString)
itm.SubItems.Add(reader("Harvest").ToString)
itm.SubItems.Add(reader("Special").ToString)
itm.SubItems.Add(reader("Other").ToString)
itm.SubItems.Add(reader("Total").ToString)
ListView1.Items.Add(itm)
End While
conn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
conn.Dispose()
End Sub
|
|
|
|
|
Hi,
this is how i access connection string from app.config file
Public Shared CONNECTSTRING As String = System.Configuration.ConfigurationSettings.AppSettings("conn")
and I am not able to see your app.config file but the app.config file for above code goes like this...
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="conn" value="Data Source=servername;Initial Catalog=dbname;User ID=userid; Password=password;"/>
</appSettings>
</configuration>
Het Waghela
Be Humble in Victory and Strong in Defeat.
Het Waghela, Blog|Het Waghela DotNet Questions Link|More Links
|
|
|
|
|
I'm running an .exe file (which I did not create) using a Process class and it's accompanying .StartInfo data as follows:
m_Process = New Process
With m_Process.StartInfo
.FileName = "cmd.exe"
.Arguments = "/C " & CompleteCommandLine
.UseShellExecute = False
.CreateNoWindow = True
.WindowStyle = ProcessWindowStyle.Normal
.RedirectStandardOutput = False
.RedirectStandardError = False
.RedirectStandardInput = False
End With
m_Process.EnableRaisingEvents = True
AddHandler m_Process.Exited, AddressOf UniqueProcessThread_Exited
m_Process.Start()
G_RenderProcessID = m_Process.Id
This allows me to have an asynchronous process that runs my command-line application, but I can get the processid in case I need to kill the process prematurely.
However, the killing of this process by it's id *only* kills my process--not any child tasks that the .exe may have spawned. Is there a way to forcibly kill *every* task that has been spawned by my process using only the processid I have using vb.net?
|
|
|
|
|
Hello,
VB6
Is it possible to use a SUB to assign values to variables and then
call the SUB throughout the program to use the variables?
Let's say I have a SUB in myDates.bas
SUB myDates()
curDate = Date
Tomorrow = blah blah blah
Yesterday = blah blah blah
End Sub
From my FORM I do something like....
Form_Load()
Call myDates
Text1.Text = curDate
Text2.Text = Yesterday
End Sub
Thanks in advanced!
---- Mike
|
|
|
|
|
This can be done in 2 ways,
1) is passing the value to sub by ref, and
2) is using form/module/class/global variable wherever you are using
(there could be more solutions to this)
hope your problem is solved!
Het Waghela
Be Humble in Victory and Strong in Defeat.
Het Waghela, Blog|Het Waghela DotNet Questions Link|More Links
|
|
|
|
|
I am trying to edit the decimal part of a number so if a person enters
40.25
i can chane it to
40.375
but i need it to work with any whole number any ideas?
I was thinking i could use:
dim a as decimal
dim b as integer
dim c as decimal
a = textbox1.text
b = textbox1.text
if a - b = .25 then
c = b + .375
textbox2.text = c
I wished we used the metric system in the US would make my like easy
1. Out of clutter, find simplicity.
2. From discord, find harmony.
3. In the middle of difficulty lies opportunity.
Albert Einstein
three rules of work
|
|
|
|
|
What about using "mod" to get the remainder then working with that?
mod = Divides two numbers and returns only the remainder.
For Example:
40 mod 1 = 0
40.25 mod 1 = .25
So you could write something like this to get the decimal(remainder) part of any number entered:
dim d as single = input mod 1
if d = .25 then
'do something
end if
|
|
|
|
|
I am working on a mortgage calculator program in VB.net. I have created it and can input loan amount, interest rate, term and get what the monthly payment will be. The next thing I need to do is allow it to list the new loan amount and interest paid for each period of the term of the loan. I think I need to use a loop and since it will display 15 years of payments and results I need it to display partial list, hesitate, then display more of the list. I have placed a list box and am trying to get the result for the first monthly payment to subtract from the total loan amount and then display the new amount in the list box. I need help in writing the loop that will allow this to occur. Can someone help me out with this? Here is where I am now
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
'Calculate the Monthly Payment'
Dim dblAmount As Double
Dim dblMonthlyRate As Double
Dim dblMonths As Double
Dim dblMonthlyPayment As Double
'Convert input values to numeric values'
dblAmount = CDbl(txtAmount.Text)
dblMonthlyRate = CDbl(txtRate.Text) / 100 'allows interest rate to be entered whole number'
dblMonths = CDbl(txtYears.Text)
'Format input values'
txtAmount.Text = FormatCurrency(dblAmount)
txtRate.Text = FormatPercent(dblMonthlyRate)
txtYears.Text = FormatNumber(dblMonths)
'Calculate payment'
dblMonthlyPayment = -Pmt(dblMonthlyRate / 12, dblMonths * 12, dblAmount)
'Format answer'
txtMonthlyPayment.Text = FormatCurrency(dblMonthlyPayment)
'Results for listbox should be new loan balance and interest rate'
'Result should be from Loan Amount minus result in Payment field'
'Dim dblLoanInterest As Double
'Dim i As Integer
'Dim NewLine As String
'dblLoanInterest = CDbl(lstLoanInterest.Text)
'dblLoanInterest = dblAmount - dblMonthlyPayment
End Sub
|
|
|
|
|
I've spent quite a lot of man hours investigating how to save the contents of my axWebBrowser to an image in VB.NET. I've tried using BitBlt but that only saves what's been rendered to the screen, so if the web page is scrollable and not all visible it doesn't capture all of it. I tried using the HTML Element; render to DC; all that stuff, but to no avail. I was pointed to a free, downloadable executable (iecapt.exe) which does a good job of capturing a url to an image. However, if the url is generic and isn't a direct reflection of the web page viewed it does me no good.
If anyone has any suggestions I would be forever grateful,
Thanks in advance
Ben
|
|
|
|
|
Hi Everybody,
I have a directory filled with files which are all exactly 1000 bytes big. What I need to do is simply to read the files in a stream one by one and to write them again in a different directory. I'd say this is a fairly standard operation, but for some reason, all my files come out of the process at 1001 bytes!! Am I missing something? Here is my code:
For Each f As IO.FileInfo In inDirInfo.GetFiles()
Dim str As New IO.FileStream(f.FullName, IO.FileMode.Open, IO.FileAccess.Read)
Dim chunk(str.Length) As Byte
str.Read(chunk, 0, chunk.Length)
str.Close()
Dim chunkStream As New IO.MemoryStream(chunk)
WriteStream(chunkStream, outputTempPath & "\" & f.Name)
chunkStream.Close()
Next
Private Sub WriteStream(ByVal stream As IO.Stream, ByVal path As String)
Try
Dim f As New IO.FileStream(path, IO.FileMode.Create)
Dim bytes(stream.Length) As Byte
stream.Read(bytes, 0, bytes.Length)
stream.Close()
f.Write(bytes, 0, bytes.Length)
f.Close()
Catch ex As Exception
Throw ex
End Try
End Sub
By the way, I don't want to simply copy the files, since I need to transfer them in streams.
Thanks for your help...
|
|
|
|
|
Ok, nevermind... I was missing something
Here is the corrected code:
For Each f As IO.FileInfo In inDirInfo.GetFiles()
Dim str As New IO.FileStream(f.FullName, IO.FileMode.Open, IO.FileAccess.Read)
Dim chunk(str.Length - 1) As Byte
str.Read(chunk, 0, str.Length)
str.Close()
Dim chunkStream As New IO.MemoryStream(chunk)
WriteStream(chunkStream, outputTempPath & "\" & f.Name)
chunkStream.Close()
Next
Private Sub WriteStream(ByVal stream As IO.Stream, ByVal path As String)
Try
Dim f As New IO.FileStream(path, IO.FileMode.Create)
Dim bytes(stream.Length - 1) As Byte
stream.Read(bytes, 0, stream.Length)
stream.Close()
f.Write(bytes, 0, bytes.Length)
f.Close()
Catch ex As Exception
Throw ex
End Try
End Sub
|
|
|
|
|
hii
got one prob when i m trying to transfer the ASP.NET Web Application (which i ve basically done fully only on on computer) to another comp.
when we try to open this application on some other comp, it does not open n shows error... so i would like to know wat is that we r missing,in copying the file or is it something else ??
and the other comp on which we are trying to open this application is working properly for ASP.NET Web Applications...
hope my prob ll be solved..
thanks
|
|
|
|
|
Gee, it sure would help if you told us what the error was.
Is IIS pointing to the right directory ? Does the target machine have the .net framework installed ? Was it installed after IIS ( so that IIS knows about ASP.NET ) ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
thanks...
the prob got solved.. but still the Web Application is not getting debugged...
this is the error i got while debugging any asp.net application on VB.NET
**************************************************************
Error while trying to run project: Unable to start debugging on the web server. Server side error occured on sending debug HTTP request
Make sure the server is operating corerclty. Verify that there are no syntax errors in Web.config by doing a Debug, Start without Debugging.
***********************************************************
i tried the start without debugging option but its working properly there... cant get wat the exact prob is ??
AND..
also when i open the Microsoft Visual Stdio.NET..n see the Debug--->Process.. i dont find the aspnet_wp.exe there.. is there any prob in the .NET Framework >??
i think that is the prob... but not sure how to sort it out ??
|
|
|
|
|
I've had this in the past, and I found an article on MSDN that showed me how to fix it. I recommend googling your error message in quotes, you're bound to find the solution that way.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
How can I change the design of report at run time through VB.NET code? is it possible? actuallu I want to create an application where users can set their own report desigh.
|
|
|
|
|