|
Not sure if this will work but...
could you not make prog1 com visible and then expose the function in prog1 that you want prog2 to call when it gets to a specific point in its processing?
I've used this process to get jscript code sitting behind an Internet Explorer page to call a function in my vb.net app
|
|
|
|
|
Hi,
You need interprocess synchronization! There are several methods, but as I'm not an expert at this I'll just give one simple and possibly naive example using a named mutex.
Process1:
using System;
using System.Diagnostics;
using System.Threading;
static void Main() {
String mutexName = Guid.NewGuid().ToString();
Process p = Process.Start(@"Process2", mutexName);
Console.WriteLine("Waiting for Process2 to create the mutex {0}", mutexName);
Mutex m = null;
do {
try {
m = Mutex.OpenExisting(mutexName);
} catch (WaitHandleCannotBeOpenedException) {
Thread.Sleep(50);
}
} while (m == null);
Console.WriteLine("Process1 has opened the mutex, waiting for release");
if (m.WaitOne(20000)) {
Console.WriteLine("Mutex was released");
} else {
Console.WriteLine("Wait period exceeded");
}
Console.WriteLine("Press enter to exit");
Console.ReadLine();
}
Process1 starts Process2 passing the desired name of the synchronisation object.
Process1 then polls until the Mutex has been created by Process2.
Process1 can now wait for Process2 to release the Mutex.
Process2:
static void Main(String[] args) {
Console.WriteLine("Process2 created mutex {0}", args[0]);
Mutex m = new Mutex(true, args[0]);
Console.WriteLine("Process2 simulating work for 5 seconds ...");
Thread.Sleep(5000);
m.ReleaseMutex();
Console.WriteLine("Process2 released mutex ...");
Console.WriteLine("Process2 doing something else ...");
Thread.Sleep(5000);
Console.WriteLine("Press enter to exit");
Console.ReadLine();
}
There are several articles here on CodeProject. Try searching for interprocess communication or synchronisation.
Alan.
|
|
|
|
|
thank you very much , this is exactly what i need, excellent thanks
|
|
|
|
|
Hi,
I am developing a vb.net application in which i uploading some paramenters which is given below "FirstName,MiddleName,LastName,MyImage".
Uploading is done successfully but image is not showing at webpage. It is uploading FirstName, MiddleName, LastName not Myimage.
My Code is below:
myUri = New Uri("https://www.mysite.com/apis/CreateMyContact.cfm")
data = data.Append("&FirstName=" & System.Web.HttpUtility.UrlEncode(Dharm))
data = data.Append("&MiddleName=" & System.Web.HttpUtility.UrlEncode(Chand))
data = data.Append("&LastName=" & System.Web.HttpUtility.UrlEncode(Dhingra))
data = data.Append("&NickName=" & System.Web.HttpUtility.UrlEncode(Dharmu))
Dim fs As System.IO.FileStream = Nothing
Dim imgByte() As Byte = Nothing
Try
fs = System.IO.File.Open(image_path, IO.FileMode.Open, FileAccess.Read)
ReDim imgByte(fs.Length)
fs.Read(imgByte, 0, fs.Length)
fs.Close()
fs.Dispose()
fs = Nothing
Catch ex As System.Exception
End Try
If Not IsNothing(imgByte) Then
data = data.Append("&PhotoBinary=" & System.Web.HttpUtility.UrlEncode(imgByte)) 'image_path)) '
End If
'Create a byte array of the data we want to send
Dim requestBytes As Byte() = System.Text.UTF8Encoding.UTF8.GetBytes(data.ToString())
Dim oWeb As New System.Net.WebClient()
oWeb.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
Try
Dim bytRetData As Byte() = oWeb.UploadData(myUri, "POST", requestBytes)
Catch ex As WebException
End Try
This code is working successfully but image is not uploading.
Please guide me if i did wrong something in code.
Regards
Dharmchand dhingra
|
|
|
|
|
Remove all of your Try/Catch garbage since you're just eating errors and not showing them or reporting them in any way. If you're code is running into a problem, you'll never know it.
|
|
|
|
|
Hi, Thanks for reply.
In this code, no any error is coming. I am able to add records successfully on server side but at server image is not displaying. I debug this code and there is no any error occurred.
Any suggestion...
Regards
Dharmchand Dhingra
|
|
|
|
|
Hi All,
In my sql database table, date is stored as "09/15/2009" i.e. in "MM/dd/YYYY" format.
Now i want to convert this in to "dd/MM/YYYY" i.e.15/09/2009. How to do this?
I tried the following:
Date cdate = #09/15/2009# ( retrieved from database)
Dim ddto As string
ddto = cdate.ToString("dd/MM/yyyy") --> get converted to string
Dim conDate As Date
conDate = DateTime.Parse(ddto,Globalization.CultureInfo.CreateSpecificCulture("pt-US"))
Using above i am not able to convert the date back from string format to date format using Parse function. I want finally the date format as dd/MM/YYYY instead of string format. How to do this?
Thanks.
|
|
|
|
|
jeshra279 wrote: In my sql database table, date is stored as "09/15/2009" i.e. in "MM/dd/YYYY" format.
No, its simply stored as a number. The display format is based on your SQL Server settings.
You do not need to convert it to another format to work with it, only when you want to display it. Then you do a tostring with the required format - just look in the help for date format, it gives loads of examples.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
It is stored as Date format as in my sql database table column datatype is Date.
I need to convert this to dd/MM/YYYY format but with date datatype, not in string.
|
|
|
|
|
As Bob said previously a Date datatype does not have a format, it merely holds a number representing a date. Only when you need to display it on an output device does it get formatted, and this is done by converting it to a string using a standard or custom format.
|
|
|
|
|
I know it has to be converted to string, but if i convert this to a string instead of date, I am not able to get correct result using the command:
cmd = New SqlCommand("SELECT [Client ID] FROM client_details WHERE [Date of Joining] <= '" + dateofj + "'GROUP BY [Client ID]", con)
The above results in incorrect data if i use this as an string, thats why i want to convert this into Date format.
pls let me know how to convert this into date format.
|
|
|
|
|
jeshra279 wrote: pls let me know how to convert this into date format.
Sorry, I don't understand what you are saying, I thought this was a Date type not a string.
|
|
|
|
|
jeshra279 wrote: + dateofj +
Is where your problem lies I suspect. I expect it is in a format something like 10/10/2009 which can either be DD/MM or MM/DD. Put it into a format like '10 Oct 2009' so that SQL Server can be certain of the format.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Or use a SqlParameter in which case it can be passed directly as a date without having to worry about format at all.
|
|
|
|
|
A double advice:
- store dates and datetimes as such in the database, never store them as strings;
- pass dates and datetimes as SQL paramters, avoid passing them as strings.
If you do both, you'll never have any date formatting problems, as there no longer is any formatting going on. Formatting should be relevant only in the user interface.
|
|
|
|
|
As per Your 2nd point, am i passing the dates and datetimes as SQL paramters in my following select command:
cmd = New SqlCommand("SELECT [Client ID] FROM client_details WHERE [Date of Joining] = '" + dateofj + "'GROUP BY [Client ID]", con)
|
|
|
|
|
No you are not. You are passing a string, and C# is implicitly calling dateofj.ToString() to perform a string concatenation afterwards; that is where the regional settings are sneaking in your code.
You need this[^] to be safe.
|
|
|
|
|
Instead of
cmd = New SqlCommand("SELECT [Client ID] FROM client_details WHERE [Date of Joining] = '" + dateofj + "'GROUP BY [Client ID]", con)
use:
cmd = New SqlCommand("SELECT [Client ID] FROM client_details WHERE [Date of Joining] = @DateOfJ GROUP BY [Client ID]", con)
cmd.Parameters.AddWithValue(@DateOfJ, YourDateValueHere)
|
|
|
|
|
Hey guys I am currently making a program that will allow a user to open/create a file and then after adding data to the file
he/she can search the file by Record number. But i am trying to come up with a If statement that will test if the Recordnumber
the user enters is NOT FOUND then display an error message, I have written this so far, but it doesn't like how I am
trying to convert a string to a double. THANKS for the HELP
Module modulePersonRec
Structure personRecord
<VBFixedString(7)> Public RecordNum As String
<VBFixedString(9)> Public SS As String
<VBFixedString(40)> Public name As String
<VBFixedString(10)> Public Tele As String
<VBFixedString(2)> Public lineBreak As String
End Structure
Public datafile As String
Public person As personRecord
Public position As Long
Public lastrec As Long
Public RecLength As Long
Public LastRecord As Integer
Public filelength As Long
Public indexSS(100) As String
Public indexKey(100) As Long
End Module
Private Sub btnGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGet.Click
'*****************************************************88
'THIS SUBROUTINE WILL ALLOW THE USER TO FIND A RECORD
'BASED ON THE RECORD NUMBER THE USER ENTERS INTO
'A REQUIRED FIELD. IF THE RECORD IS FOUND THEN
'THE CORRESPONDING DATA WILL BE DISPLAYED
'****************************************************
FileGet(1, person, Val(txtRecNum.Text))
If person.RecordNum <> Val(txtRecNum.Text) Then
MessageBox.Show("Record Does not exist", "RandomFile", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
FileGet(1, person, Val(txtRecNum.Text))
txtSSN.Text = person.SS
txtName.Text = person.name
txtTele.Text = person.Tele
End If
End Sub
I AM ALSO HAVING A PROBLEM WHEN TRYING TO ALLOW UPDATES TO A SPECIFIC RECORD, WHEN I LOOK UP A RECORD NUMBER AND THEN
TRY SAVING THE CHANGES IT DOES NOT CHANGE THAT SPECIFIC RECORD WHAT IT IS DOING RIGHT NOW IS IT WILL ADD IT TO THE FILE
BUT IT THEN APPENDS OR ERASES THE NEXT FILE SO IF I HAD 3 RECORDS AND I SAY I WANNA CHANGE THE 1ST REC, IT WILL APPEND OR ERASE ITSELF TO THE 2ND POSITION IN THE FILE AND THE PREVIOUS 2ND RECORD WILL NOW BE DELETED. ???? IT IS HOWEVER SAVING JUST
NOT TO THE RIGHT INDEX
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
'**********************************************
'THIS SUBROUTINE WILL UPDATE ANY CHANGES
'THE USER ENTERS TO A SPECIFIC RECORD
'HE/SHE FINDS AFTER SEARCHING BY REC NUM
'**********************************************
'Update the information of an person.
' person.RecordNum = Val(txtRecNum.Text)
person.name = txtName.Text
person.SS = txtSSN.Text
person.Tele = txtTele.Text
FilePut(1, person, )
End Sub
modified on Wednesday, December 9, 2009 3:18 AM
|
|
|
|
|
WHy does this assignmnet reek of homework??
|
|
|
|
|
Sorry its just a program needed for class and I have it almost working but cant find a way around my problem I am running into
|
|
|
|
|
OK, this is the first time I've ever heard of anyone teaching FileGet/FilePut in a VB.NET class. The only time I've ever seen anyone actually using it is in VB6 projects converted to VB.NET.
You don't need the record number in the data since each is going to be at a certain position anyway. When the use enters a record number, it'll go and get that record from the file, even if it's empty. So, there's no need to check the RecordNumber returned by the person object because you already got the record at that position.
The question becomes, did you get anything back from the record? Is person returning Nothing?
Your second problem is in the FilePut call. You're not telling FilePut which position in the file to write the record to.
|
|
|
|
|
hi,
pls anyone try to solve my problem... i need to fetch some thousands of records and insert/export that to excel file using vb.net...
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cnt As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim xlApp As Object
Dim xlWb As Object
Dim xlWs As Object
Dim recArray As Object
Dim strDB As String
Dim fldCount As Integer
Dim recCount As Long
Dim iCol As Integer
Dim iRow As Integer
strDB = "UNOGI\UNO;database=Test;uid=sa;pwd=welcome3#" 'here am getting the following error "Could not find installable ISAM."
cnt.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDB & ";")
rst.Open("select top 10000 * from Test.dbo.CustomerDetail", cnt)
xlApp = CreateObject("Excel.Application")
xlWb = xlApp.Workbooks.Add
xlWs = xlWb.Worksheets("Sheet1")
xlApp.Visible = True
xlApp.UserControl = True
fldCount = rst.Fields.Count
For iCol = 1 To fldCount
xlWs.Cells(1, iCol).Value = rst.Fields(iCol - 1).Name
Next
If Val(Mid(xlApp.Version, 1, InStr(1, xlApp.Version, ".") - 1)) > 8 Then
xlWs.Cells(2, 1).CopyFromRecordset(rst)
Else
recArray = rst.GetRows
recCount = UBound(recArray, 2) + 1
For iCol = 0 To fldCount - 1
For iRow = 0 To recCount - 1
If IsDate(recArray(iCol, iRow)) Then
recArray(iCol, iRow) = Format(recArray(iCol, iRow))
ElseIf IsArray(recArray(iCol, iRow)) Then
recArray(iCol, iRow) = "Array Field"
End If
Next iRow
Next iCol
' Transpose and Copy the array to the worksheet,
' starting in cell A2
xlWs.Cells(2, 1).Resize(recCount, fldCount).Value = _
TransposeDim(recArray)
End If
' Auto-fit the column widths and row heights
xlApp.Selection.CurrentRegion.Columns.AutoFit()
xlApp.Selection.CurrentRegion.Rows.AutoFit()
' Close ADO objects
rst.Close()
cnt.Close()
rst = Nothing
cnt = Nothing
' Release Excel references
xlWs = Nothing
xlWb = Nothing
xlApp = Nothing
End Sub
Function TransposeDim(ByVal v As Object) As Object
' Custom Function to Transpose a 0-based array (v)
Dim X As Long, Y As Long, Xupper As Long, Yupper As Long
Dim tempArray As Object
Xupper = UBound(v, 2)
Yupper = UBound(v, 1)
ReDim tempArray(Xupper, Yupper)
For X = 0 To Xupper
For Y = 0 To Yupper
tempArray(X, Y) = v(Y, X)
Next Y
Next X
TransposeDim = tempArray
End Function
in the above code i got some error, if anyone knows any other way pls try to help me resolve as soon as you can... thanks in advance..
|
|
|
|
|
|
do u know any other way to do this bulk insert operation to excel sheet from vb.net
|
|
|
|
|