|
Would you show me an example of the code you are referring to? How should I convert a string object to a custom .net object?
|
|
|
|
|
Quote: How should I convert a string object to a custom .net object? No idea, the question does not really make sense, since String is already a .NET object.
|
|
|
|
|
|
I'll attempt to answer your question, but if it were me, I think I would re-design this solution. Do you really need to store the letter in the database ? Maybe create a template letter, give it a unique document ID, then you could store multiple records with the student ID, template ID and sequence number.
To answer your question ...
Create a class and call it LetterDetail; at a minimum it would have a string to store the letter.
Create another class and call it MailedLetters; this would contain a List(Of LetterDetail)
The second class gives you the ability to have as many letters as you want grouped together.
Within the second class, you would need 2 methods, Save and Load. This would serialize the object to an XML string which you could then save in the database.
I'll give you some rough code for serialization ...
Public Shared Function Load(sFname As String) As MailedLetters
Dim xr As XmlReader
Dim settings As XmlWriterSettings = New XmlWriterSettings()
settings.Indent = True
settings.IndentChars = (ControlChars.Tab)
settings.OmitXmlDeclaration = True
Dim obj As New MailedLetters
Dim mySerializer As New XmlSerializer(obj.GetType)
xr = XmlReader.Create(sFname)
obj = mySerializer.Deserialize(xr)
xr.Close()
xr = Nothing
Return obj
End Function
Instead of serializing to a file, you want to serialize it to a string.
Sub Save(sFname As String)
Dim xw As XmlWriter
Dim mySerializer As New XmlSerializer(Me.GetType)
Dim settings As XmlWriterSettings = New XmlWriterSettings()
settings.Indent = True
settings.IndentChars = (ControlChars.Tab)
settings.OmitXmlDeclaration = False
xw = XmlWriter.Create(sFname, settings)
mySerializer.Serialize(xw, Me)
xw.Close()
End Sub That's the best I can do for you, hope it helps.
|
|
|
|
|
Hi We are calling the webservice function from vb script by using "MSSOAP.SoapClient30", the function returns the byte array and we are saving that as *.jar file below is the sample code
============================================================
sAdminSOAPUrl = "http://testapp.com:80/test/ecs/webservices/AdminService?wsdl"
Dim vaData
Set soapClient3 = CreateObject("MSSOAP.SoapClient30")
Call soapClient3.MSSoapInit(sAdminSOAPUrl, "AdminService", "AdminService")
soapClient3.ConnectorProperty("EndPointURL") = sAdminSOAPUrl
vaData = soapClient3.exportDeployment("test","test","test_data")
If (IsArray(vaData)) Then
rgData = vaData
WScript.Echo rgData
sFilename = sPath & "xplbio.jar"
hFile = FreeFile()
Open sFilename For Binary As #hFile
Put #hFile, , rgData
Close #hFile
Dim fso As New FileSystemObject
fso.CopyFile sFilename, sPath & sExportName & ".jar"
fso.DeleteFile sFilename, True
End If
============================================================
now we are trying to use the "MSXML2.ServerXMLHTTP.6.0" instead of "MSSOAP.SoapClient30" but facing issues while writing the response into *.jar file and its being corrupt.
we have tried by channging the respose header as below but facing the same issue
"Content-Type", "text/xml; charset=utf-8",
"Content-Type" "multipart/form-data",
"Content-Type" "application/x-www-form-urlencoded",
is there any thing which I am missing please suggest, below is the sample updated code
==============================================================
' Namespaces.
Dim NS, NS_SOAP, NS_SOAPENC, NS_XSI, NS_XSD
NS_SOAP = "http://schemas.xmlsoap.org/soap/envelope/"
' Creates an XML DOM object.
Set DOM = CreateObject("MSXML2.DOMDocument.6.0")
' XML DOM objects.
Dim Envelope, Body, Operation, Param
Const URL = "http://testapp.com:80/test/ecs/webservices/AdminService?wsdl"
' Creates the main elements.
Set Envelope = DOM.createNode(1, "soap:Envelope", NS_SOAP)
DOM.appendChild Envelope
Set Body = DOM.createElement("soap:Body")
Envelope.appendChild Body
' Creates an element for the exportDeployment function.
Set Operation = DOM.createNode(1, "exportDeployment","")
Body.appendChild Operation
' Creates an element for the exportDeployment parameter
Set Param = DOM.createNode(1, "username","")
Param.Text = "test"
Operation.appendChild Param
Set Param1 = DOM.createNode(1, "password","")
Param1.Text = "test"
Operation.appendChild Param1
Set Param2 = DOM.createNode(1, "deploymentName","")
Param2.Text = "test_data"
Operation.appendChild Param2
DIM test
Set XMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
XMLHTTP.Open "POST", URL, False
XMLHTTP.setRequestHeader "Content-Type", "multipart/form-data; User-Agent: SOAP Sdk"
XMLHTTP.setRequestHeader "SOAPAction", URL
XMLHTTP.send DOM.xml
' Loads the response to the DOM object.
DOM.LoadXML XMLHTTP.responseXML.xml
' XML DOM objects.
Dim NodeList, Element, vaData
' Searches for the exportDeploymentReturn object, which contains the value.
Set NodeList = DOM.getElementsByTagName("*")
For Each Element in NodeList
If Element.tagName = "exportDeploymentReturn" Then
vaData = Element.Text
Exit For
End If
Next
If (IsArray(vaData)) Then
rgData = vaData
WScript.Echo rgData
sFilename = sPath & "xplbio.jar"
hFile = FreeFile()
Open sFilename For Binary As #hFile
Put #hFile, , rgData
Close #hFile
Dim fso As New FileSystemObject
fso.CopyFile sFilename, sPath & sExportName & ".jar"
fso.DeleteFile sFilename, True
End If
====================================================================
|
|
|
|
|
This might be old thread (8 month) but since nobody answered...
I don't know if this will fix your issue, but this part is wrong:
XMLHTTP.setRequestHeader "Content-Type", "multipart/form-data; User-Agent: SOAP Sdk"
replace with
XMLHTTP.setRequestHeader "Content-Type", "multipart/form-data"
XMLHTTP.setRequestHeader "User-Agent", "SOAP Sdk"
setRequestHeader accept only 1 new header at the time and add it to the stack. When the request is sended, the header are "ordered" (for exemple, User-Agent is sent to top of list) see:
[https://msdn.microsoft.com/fr-fr/library/ms536752(v=vs.85).aspx]
|
|
|
|
|
Good Afternoon,
I have a problem with the focus control(set focus) after showing the dialogs form, can you help me to resolve it ?
Example code:
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Form2.ShowDialog()
End Sub
after i show the second form, i can't set focus on a textbox in first form when the second form is closed. i used this code..
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
form1.textbox1.focus
End Sub
Help me please.....Thx
|
|
|
|
|
Me.Close()
How do you think the code on this form will continue to run after the statement above?
See Richard Deemings explanation(s)
modified 13-Nov-16 3:29am.
|
|
|
|
|
The code in the same procedure will continue to run, as will any code in the Closing and Closed event handlers.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yes, but the code in question is not in either of those places.
|
|
|
|
|
Yes it is.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
form1.textbox1.focus
End Sub
Calling Close on the previous line won't prevent the second line from executing.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
That's a button click event, not a Closing or Closed. I just ran a simple test (added a MessageBox.Show after) and although the debugger continued in the method after the call to Close , the MessageBox did not get displayed.
|
|
|
|
|
If you've just closed the last open form in the application, the message box doesn't show. That seems like a bug to me.
If there's another form still open, the message box shows as expected.
Try this example from LINQPad:
void Main()
{
Application.Run(new Form1());
}
class Form1 : Form
{
public Form1()
{
var btn = new Button();
btn.Text = "Open Form2";
btn.Click += btn_Click;
Controls.Add(btn);
}
private void btn_Click(object sender, EventArgs e)
{
var form = new Form2();
form.Show();
}
}
class Form2 : Form
{
public Form2()
{
var btn = new Button();
btn.Text = "Close me";
btn.Click += btn_Click;
Controls.Add(btn);
}
private void btn_Click(object sender, EventArgs e)
{
Close();
Console.WriteLine("Closed");
MessageBox.Show("Closed");
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Better yet, why is code in Form2 referencing anything at all in Form1?
It should be the job of Form1 to set focus on one of it's controls, not Form2.
Or am I missing something?
|
|
|
|
|
That would be a better solution.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello !
I'm using VB.net 2013 and entity Framework 6.
I have a form with a bindingsource.
On the form's load event i have this instruction :
Myobjectbindingsource.datasource=(From t in context.Myobjects Select t).Tolist
I have another event :
Private Sub MyObjectbindingsource_CurrentChanged(sender As Object, e As EventArgs) Handles MyObjectbindingsource.CurrentChanged
Messagebox.show("Hello")
End Sub
If context.myobjects is not empty , before the form is shown , the message "Hello" is displayed 3 times.
My question is why the currentChanged event is called 3 times , because there's only 1 instruction that change items on bindingsource ?
Thank you !
|
|
|
|
|
The CurrentChanged event is raised whenever the Current property changes for any of the following reasons:
- The current position of the List changes.
- The DataSource or DataMember properties change.
- The membership of the underlying List changes, which causes Position to refer to a different item. Examples include adding or deleting an item before the current item, deleting or moving the current item itself, or moving an item to the current position.
- The underlying list is refreshed by a new sorting or filtering operation.
First thing that happens is #2, and I'd expect #1 after that (move to first position in the set), add #4 and you have three calls.
Which is mostly guessing, since I cannot see all code.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you , but actually I want to display the message only once , when the current position change. What condition should I use to distinguish from 2 other cases ?
Thank you !
|
|
|
|
|
Keep a reference to the last known "current" value. If the event occurs, then "current" will already point to something new. If it doesn't, than nothing has changed and you can ignore it.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello !
I have a vb.net 2013 application.
On application Properties , I have configured as startup form a form that act as a login form.
(After this login form is closed , the main form is displayed.)
On Shutdown mode I have " When last form closes"
But now , when I click the x button to close my main form , the form is closed but the application is not fully closed and is still running.
I've tested and I've found that when the form is closing Application.OpenForms.Count is 1. So as I've configured this is the last form and closing this should close the application but this is not happening.
What can I do ?
|
|
|
|
|
Have you started any other threads in your application? An application will not close if there are any threads still running.
Cheers,
Mick
------------------------------------------------
It doesn't matter how often or hard you fall on your arse, eventually you'll roll over and land on your feet.
|
|
|
|
|
Ok , let me explain :
As I've said , the first form is the Loginform,After the login form is closed , the Mainform is open.
On LoginForm , I have 2 instruction that seems to have relation with threads ( I don't know for sure ) :
System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
System.Math.Max(System.Threading.Interlocked.Decrement(n), n + 1)
After the loginform is closed nothing happens. But when I try to close the MainForm , as I've said the application does not terminate.
What can I do ?
Thank you !
|
|
|
|
|
No, those statements do not start threads, but are designed for other threads to safely access "i". This is a tricky sort of bug to find. You will have to get into the debugger, allow the forms to close, and then pause the application and open the "threads" view window. Take a look at the threads that are still running - there'll have to be at least one of them. Examine each thread, and see if they are executing any of your code. You may also have to check the call stack for each thread, if they are executing native code, and see if any of you call got it to that point. Once you find out if any of your .net code is to blame or not, you can then figure out how it got into its state.
Cheers,
Mick
------------------------------------------------
It doesn't matter how often or hard you fall on your arse, eventually you'll roll over and land on your feet.
|
|
|
|
|
On all my forms I have several queries from entity framework.
when I close my main form , as I've said my application does not ends. I have paused as you've said , and on Threads list I have all these queries that are in my main form.
I did another test.
I have open several other forms.And after I have closed all these forms. And when I close the mainform , the application did not finish so I've paused again and on the thread list I see a list with all these queries from all the forms that I've open.
But it's strange because these queries are executed by demand , I mean when I click on buttons on these forms.
What can I do ?
Thank you !
|
|
|
|
|