|
Hi there
I've started using web services in VB.net, and it works great; I'm actually not creating the web services themselves, rather calling them from my Windows Form application. I use the "add web reference" function, and everything works great for simple services which take parameters such as string, double, datetime etc. and return a string. I now need to use a bunch of services which take a "MAP" as parameter, which from what I understand is an array of string parameters. The MAP class has only two properties, Key and Item.
I haven't managed to input the parameters, cauz I don't know where to start. I've tried as follows
Dim Map As New WebServices.WebServicePerformance1.Map<br />
<br />
Map.item(0).value = ptfCode<br />
Map.item(1).value = "VL_BASE100_DTD"<br />
Map.item(2).value = "codeTypePart"<br />
Map.item(3).value = "PTF_INDICES"<br />
Map.item(4).value = "0"<br />
<br />
Dim Res As String = Perf.calculReportMultiDevise(Map)<br />
<br />
Return Res
I have a working sample in Excel VBA, which goes as follows:
Sub getValorisationPtf_bench(codeTypePart As String, ptfCode As String, typeindices As String, deviseCalcul As String, periodicite As String, startDate As String, endDate As String, colonneAffiche As String, startRowIndex As Integer, startColIndex As Integer)<br />
<br />
Dim Connector As SoapConnector<br />
Dim Serializer As SoapSerializer<br />
Dim Reader As SoapReader<br />
<br />
<br />
Set Connector = New HttpConnector<br />
Set Serializer = New SoapSerializer<br />
Set Reader = New SoapReader<br />
' construction du message Soap<br />
Connector.Property("EndPointURL") = URL<br />
' Connector.Property("ConnectTimeout") = 120000<br />
Connector.Property("Timeout") = 300000<br />
Call Connector.Connect<br />
Connector.Property("SoapAction") = URIPERF & "#" & "calculReportMultiDevise"<br />
Call Connector.BeginMessage<br />
<br />
Serializer.Init Connector.InputStream<br />
<br />
Serializer.StartEnvelope , ENC<br />
Serializer.SoapNamespace "xsi", XSI<br />
Serializer.SoapNamespace "SOAP-ENC", ENC<br />
Serializer.SoapNamespace "xsd", XSD<br />
<br />
' Construction des paramètres d''appel<br />
Serializer.StartBody<br />
Serializer.StartElement "calculReportMultiDevise", URIPERF, , "ns1"<br />
Serializer.SoapAttribute "EncodingStyle", , "http://schemas.xmlsoap.org/soap/encoding/", "SOAP-ENV"<br />
Serializer.StartElement "Code", "http://xml.apache.org/xml-soap", , "ns2"<br />
Serializer.SoapAttribute "type", , "ns2:Map", "xsi"<br />
addMessageEntry Serializer, "codeActif", ptfCode, "xsd:string"<br />
addMessageEntry Serializer, "codereq", "VL_BASE100_DTD", "xsd:string"<br />
addMessageEntry Serializer, "typepart", codeTypePart, "xsd:string"<br />
addMessageEntry Serializer, "typecalcul", "PTF_INDICES", "xsd:string"<br />
<br />
Serializer.EndElement<br />
<br />
Serializer.StartElement "colonneAffiche"<br />
Serializer.SoapAttribute "type", , "xsd:string", "xsi"<br />
Serializer.WriteString colonneAffiche<br />
Serializer.EndElement<br />
<br />
Serializer.EndElement<br />
Serializer.EndBody<br />
Serializer.EndEnvelope<br />
<br />
Connector.EndMessage<br />
<br />
Reader.Load Connector.OutputStream<br />
<br />
If Not Reader.Fault Is Nothing Then<br />
MsgBox Reader.FaultString.text + " not reader ", vbExclamation<br />
Else<br />
'parseDom Reader.Dom, startRowIndex, startColIndex<br />
displayValoPtfbench Reader.Dom.text, colonneAffiche, startRowIndex, startColIndex<br />
End If<br />
<br />
If Not Reader.Fault Is Nothing Then<br />
MsgBox Reader.FaultString.text, vbExclamation<br />
End If<br />
<br />
End Sub
From my poor understanding it's serializing an XML file, but I do not know how to do that in .net. I'm pretty sure there is a simple way in .net than in VBA, without calling the connection, data reader etc., as I already have the proxy classes automatically generated.
Anybody capable of helping me get that up and running in .net??
Many Thanks in advance...
JM
|
|
|
|
|
In the VBA code you supplied, it appears that "Map" is a collection of key/value pairs (built using the addMessageEntry calls.) You've added the values in your VB.NET code, but not the keys they go to ("codeActif", "codereq", ...) So, in your VB.NET code, you'd do something like:
Map.Add("codeActif", ptfCode.ToString())
Map.Add("codereq", "VL_BASE100_DTD")
Map.Add("typepart", codeTypePart.ToString())
Map.Add(typecalcul", "PTF_INDICIES")
Mind you, this is just a guess, since you haven't provided anyn details about what a "Map" object is. I'm guessing that it represents a collection of key/value pairs, judging by the VBA code...
|
|
|
|
|
I want the DataGridView to select for methe row that contains 1234 in CustomerID column.
thanks
Shimi
|
|
|
|
|
Can you be more specific.
what is methe?
Shay Noy
|
|
|
|
|
|
this worked:
Private Sub ctlSpan_TextChanged(ByVal sender As Control, ByVal e As System.EventArgs) Handles ctlSpan.TextChanged<br />
With CustomersDataGridView<br />
If .Columns.Contains("CustomerID") Then<br />
For Each row As DataGridViewRow In .Rows<br />
If row.Cells("CustomerID").Value.ToString = sender.Text Then<br />
If row.Cells("CustomerID").Value IsNot Nothing Then<br />
If Not row.Selected Then row.Selected = True<br />
End If<br />
End If<br />
Next<br />
End If<br />
End With<br />
End Sub
Shimi
modified on Sunday, December 30, 2007 11:39:28 PM
|
|
|
|
|
I've been trying to get this to work for weeks now without success.
I have two rich text boxes on my form and I'm trying to create a load_event so that
each one of the rich text boxes reads from a different text file saved on the root of C drive.
The richTextBox1 is working fine but richTextBox2 is not? What am I doing wrong?
Also, when F5 key is pressed(shortcut for MainMenuItem1) the following needs to happen:
the time stamp is put into whichever box has focus and the contents of that box need to be written
to a text file on C drive. All of this is working fine for richTextBox1 but not for richTextBox2.
Can anyone please help me??? I would greatly appreciate it!
Thanks, Hedo
Public Class Form1
Inherits System.Windows.Forms.Form
Dim firsthasfocus As Boolean
Dim secondhasfocus As Boolean
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem2})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.Shortcut = System.Windows.Forms.Shortcut.F5
Me.MenuItem1.Text = "DateTimeStamp"
Me.MenuItem1.Visible = False
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
If firsthasfocus Then
richTextBox1.Text = richTextBox1.Text & " " & Now & " "
ElseIf secondhasfocus Then
RichTextBox2.Text = RichTextBox2.Text & " " & Now & " "
Dim richTextBox1 As New RichTextBox
End If
Dim FILE_NAME As String = "C:\textfile1.txt"
If System.IO.File.Exists("C:\textfile1.txt") = True Then
'The following line of code will overwrite the log with the current
'contents of the text box(when F5 key is pressed),
'if you wish to append(add) text instead of
'overwriting it then just add "True" in the parenthesis after the path
' so it looks like this("C:\textfile1.txt", True)
Dim objWriter As New System.IO.StreamWriter("C:\textfile1.txt")
objWriter.Write(richTextBox1.Text)
objWriter.Close()
MsgBox("Saved")
Else
MsgBox("File Does Not Exist")
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim FILE_NAME As String = "C:\textfile1.txt""C:\textfile1.txt"
If System.IO.File.Exists("C:\textfile1.txt") = True Then
Dim objReader As New System.IO.StreamReader("C:\textfile1.txt")
RichTextBox1.Text = objReader.ReadToEnd
objReader.Close()
End If
If System.IO.File.Exists("C:\textfile2.txt") = True Then
Dim objReader As New System.IO.StreamReader("C:\textfile2.txt")
RichTextBox2.Text = objReader.ReadToEnd
objReader.Close()
Else
MsgBox("File Does Not Exist")
End If
End Sub
Private Sub RichTextBox2_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox2.GotFocus
secondhasfocus = True
firsthasfocus = False
End Sub
|
|
|
|
|
If I understood you right, this is the solution (Copy and paste):
Option Explicit On
Public Class Form1
Inherits System.Windows.Forms.Form
Dim firsthasfocus As Boolean
Dim secondhasfocus As Boolean
Const File1 As String = "C:\textfile1.txt", File2 As String = "C:\textfile2.txt"
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
If firsthasfocus Then
RichTextBox1.Text &= " " & Now & " "
If System.IO.File.Exists(File1) = True Then
Dim objWriter As New System.IO.StreamWriter(File1)
objWriter.Write(RichTextBox1.Text)
objWriter.Close()
MsgBox("Saved in " & File1)
Else
MsgBox("File " & File1 & " Does Not Exist")
End If
ElseIf secondhasfocus Then
RichTextBox2.Text &= " " & Now & " "
If System.IO.File.Exists(File2) = True Then
Dim objWriter As New System.IO.StreamWriter(File2)
objWriter.Write(RichTextBox2.Text)
objWriter.Close()
MsgBox("Saved in " & File2)
Else
MsgBox("File " & File2 & " Does Not Exist")
End If
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If System.IO.File.Exists(File1) = True Then
Dim objReader As New System.IO.StreamReader(File1)
RichTextBox1.Text = objReader.ReadToEnd
objReader.Close()
Else
MsgBox("File " & File1 & " Does Not Exist")
End If
If System.IO.File.Exists(File2) = True Then
Dim objReader As New System.IO.StreamReader(File2)
RichTextBox2.Text = objReader.ReadToEnd
objReader.Close()
Else
MsgBox("File " & File2 & " Does Not Exist")
End If
End Sub
Private Sub RichTextBox2_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox2.GotFocus
secondhasfocus = True
firsthasfocus = False
End Sub
Private Sub RichTextBox1_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.GotFocus
secondhasfocus = False
firsthasfocus = True
End Sub
End Class
Shay Noy
|
|
|
|
|
Wow! That's it. Your code works. Thanks a lot!
Thanks for the super fast response.
You've just saved me a lot of time.
I do have a few more questions.
1. How do I automate the process of creating the file1 and file2 at startup (load_event) so that I don't have to create them manually: at startup, check if file1 and file2 exists, if true, read from file1 and file2, if false, create file1 and file2. I know how to explain it but how do you say it in code?
2. How do I append logs for 30 days, on day 31, delete (or overwrite) log for day 1, on day 32 delete (or overwrite) log for day 2 and so on...
so that I always have logs for the last 30 days from today and at startup only load the latest(newest) log.
3. How do I put a calendar under a search button so when the search button is clicked, a calendar pops up and you pick a date and the log for file1 or file2 for that day gets loaded into the rtf box. I also need another button that lets you return to the current (last) log.
4. If I have a drop down menu on the form and collection items are: Up, Down, Left, Right, Front, Back and I have "Up" (or any other one) selected and the application gets closed, how do I save the setting so that when the form is loaded again, it shows the same selection it had before it was closed?
Thanks for your time.
|
|
|
|
|
Dear,
Is there anyone to give some suggestions for me? In my project, I would like to detect whether the mouse is tracking or not. I don't care where the mouse position.
First, I use Form_MouseMove function, but it can't sense when the mouse pointer arrives out of Form. Second, it can be sensed while using GetMousePos API, but it can't sense while the pointer arrive the boundary of the screen although the mouse is still jogging.
Can I sense that movement from the system? How can I write the code in VB 6.0?
Best Regards,
zawpai
|
|
|
|
|
I can't remember if this is going to apply to VB6 or not, but...
Handle the Form's MouseLeave event and you'll know when the mouse leaves your form. As for getting the mouse information after that, you'll probably have to run a Timer to fire off some code that gets the mouse position and compares it to the known coordinates of the edges of the screen. You'll probably need to use the GetMousePos function to get what you need.
You'll have to call the GetSystemMetrics[^] function to get the screen dimensions.
|
|
|
|
|
|
First, read this post[^].
I'm not looking through all that garbage to find the relevant code. Most of it's Java and the text for an agreement - hardly relevant to any VB.NET related questions.
Second, I have no idea what your question is...
|
|
|
|
|
Don't delete messages after someone has replied.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
I'd like to export specific columns into certain positions in the textfile, can you show me how?
For example - loop through row, exporting into textfile:
column 1 ---> start on 1st line Position 20 in the text file (after 19 spaces)
column 2 ---> beginning of next line.
column 3 ---> (after 39 spaces), position 40.
__________________
I know how to set get the whole line, but how to get specific values from each row.
Here's what i have that extracts all (just a snippet of my code). Please help
For rowIndex = 1 To 50
colIndex = 1
If Not (CType(oWS.Cells(rowIndex, colIndex), Excel.Range)).Value2 Is Nothing Then
For colIndex = 1 To 15
If (CType(oXL.Cells(rowIndex, colIndex), Excel.Range)).Value2 Is Nothing Then
sWrtier.Write("" + vbTab)
Else
sWrtier.Write((CType(oXL.Cells(rowIndex, colIndex), Excel.Range)).Value2.ToString() + vbTab)
End If
Next
End If
|
|
|
|
|
What is the problem?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Hi Paul,
I am trying to export each cell value as opposed to getting a whole row at a time, as they go to specific positions in the text file. Here's what i have now and i get
"Unable to cast COM object of type 'System.__ComObject' to class type 'System.Array'.
Error on line with--->" For r = 1 To UBound(arr, 1)". Can you help?
Sub MakeFixedWidth()<br />
<br />
Dim oXL As New Excel.Application<br />
Dim oWBK As Excel.Workbook = oXL.Workbooks.Open("\\nycapps01\DevFiles\SeamlessDev\Excel2Text\SampleInvoice8.xls")<br />
Dim oWS As Excel.Worksheet = CType(oWBK.Worksheets(1), Excel.Worksheet)<br />
<br />
<br />
'Dim Sizes As Object<br />
Dim arr As Object<br />
Dim r As Long ', c As Long<br />
Dim fso As Object<br />
Dim ts As Object<br />
Dim TheLine As String<br />
'Dim TestStr As String<br />
<br />
Dim names As Object = Array.CreateInstance(GetType(Integer), 10, 8, 10, 8, 10, 8, 10, 8)<br />
<br />
'Sizes = Array(4, 2, 45)<br />
arr = oWBK.ActiveSheet.UsedRange<br />
<br />
fso = CreateObject("Scripting.FileSystemObject")<br />
ts = fso.CreateTextFile("c:\blah.txt", True)<br />
<br />
For r = 1 To UBound(arr, 1)<br />
TheLine = Space(51) ' your fixed-width output<br />
<br />
Mid(TheLine, 1, 10) = oWS.Cells(r, 1)<br />
Mid(TheLine, 11, 8) = oWS.Cells(r, 1)<br />
Mid(TheLine, 19, 10) = oWS.Cells(r, 1)<br />
Mid(TheLine, 29, 8) = oWS.Cells(r, 1)<br />
Mid(TheLine, 37, 10) = oWS.Cells(r, 1)<br />
Mid(TheLine, 47, 8) = oWS.Cells(r, 1)<br />
Mid(TheLine, 55, 10) = oWS.Cells(r, 1)<br />
Mid(TheLine, 65, 8) = oWS.Cells(r, 1)<br />
ts.WriteLine(TheLine)<br />
<br />
Next r<br />
<br />
ts.Close()<br />
<br />
ts = Nothing<br />
fso = Nothing<br />
<br />
MsgBox("Done")<br />
<br />
End Sub
|
|
|
|
|
So I am using ODBC to connect to my SQL server like such:
<br />
<br />
connection = "Provider=MSDASQL;" + "Driver={SQL Native Client};" + "Server=MYSERVER;" + "Database=MYDB;" + "UID=MYUSERNAME;" + "PWD=MYPASSWORD;" + Trusted_Connection=yes;"<br />
<br />
Try<br />
Using connection As New OdbcConnection(ConnectionString)<br />
Dim command As New OdbcCommand(queryString, connection)<br />
connection.Open()<br />
<br />
Dim reader As OdbcDataReader = command.ExecuteReader()<br />
<br />
While reader.Read()<br />
station_count = reader(0).ToString<br />
End While<br />
<br />
connection.Close()<br />
reader.Close()<br />
End Using<br />
Catch ex As Exception<br />
SQLERROR = True<br />
WriteErrorLog(ex.ToString)<br />
Exit Sub<br />
<br />
End Try<br />
This is causing me a problem within my application. I wrote it using a Domain Admin which has access to the server through my SQL user, but the application needs to be deployed on a machine with much lower permission.
My question is:
1. Should I rewrite the database connection using a different method instead of ODBC
2. Is there something I can do on the server to fix this?
Thanks!
Steve
|
|
|
|
|
Why are you using the Odbc library instead of the SqlServer (SqlConnection, SqlCommand, Sqlxxxx...) specific library?
Also, if you're using TrustedConnection, it means you're using the Windows account to login to SQL Server. Specifying a username and password with SSPI (Trusted Connection = True) is pointless since it won't be used. You either specify a username and password to use (SSPI off) SQL Servers authentication, or you don't specify them and turn SSPI on to use Windows Integrated security.
You can get the various connection strings for all kinds of databases and connection options from ConnectionStrings.com[^]. There is also a small reference guide on the SQL Server connection strings here[^].
|
|
|
|
|
If I create a small custom class:
<br />
Public Class XMLNode1<br />
Private xmlHeader As String<br />
Private xmlValue As String<br />
<br />
Public Sub New()<br />
xmlHeader = Nothing<br />
xmlValue = Nothing<br />
End Sub<br />
Public Sub New(ByVal head As String, ByVal val As String)<br />
Me.propHead = head<br />
Me.propVal = val<br />
End Sub<br />
<br />
Public Property propHead()<br />
Get<br />
Return xmlHeader<br />
End Get<br />
Set(ByVal value)<br />
xmlHeader = value.ToString<br />
End Set<br />
End Property<br />
Public Property propVal()<br />
Get<br />
Return xmlValue<br />
End Get<br />
Set(ByVal value)<br />
xmlValue = value.ToString<br />
End Set<br />
End Property<br />
<br />
<br />
End Class<br />
<br />
How should i go about writing a disposal method for it?
Also, my idea of disposing a class is releasing all th eobject that class uses...Is that correct?
Please help
|
|
|
|
|
For this little class, you don't need to implement IDisposable.
You would normally implement IDisposable when your class holds onto unmanaged resources or holds onto other objects that require calling Dispose on them.
Read...[^]
|
|
|
|
|
I do have another class that uses an arraylist,xml reader, sql adapter, and sql connection.
I read about including a dispose method , but im not sure how to implement this. I guess i could just call each objects dispose method, but im curious as to add the disposal methods to my class.
|
|
|
|
|
As Dave mentioned, you generally don't need to implement IDisposable unless your class maintains unmanaged resources directly. However, if you are managing the lifetime of other managed resources that implement IDisposable you should also implement IDisposable yourself.
Take a look at this article[^] for more information.
Scott.
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]<</div>
|
|
|
|
|
Hello there!
I'm working with VB6 ( argh! I have no option) and I have a small problem,
My application has 6 forms and the main form posses 7 collections.
And the whole operation needs to work with those 7 collections (adding, deleting, counting and so on) in any Form.
My problem is: how to make those 7 collections Public or "Global"?
Ps.: I could do it in VB.Net but the current DLL's does not support .Net Framework yet.
Thanks in advance.
With Regards, Suguimoto
|
|
|
|
|
suguimoto wrote: orking with VB6 ( argh! I have no option)
Bummer. VB6 has been so dead for so long.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|