|
Hi,
I have a problem with VS2010beta2 and .NET Framework Client Profile, although I would expect the problem to be something to do with my inexperienced coding.
I have this block of code..
struct sGamePort
{
public string sgpProtocol;
public UInt16 sgpPortStart;
public UInt16 sgpPortEnd;
}
struct sGamePortItem
{
public string sgpName;
public List<sGamePort> sgpPortList;
}
List<sGamePortItem> sGames;
private sGamePort ParsePorts(string[] line)
{
sGamePort gp = new sGamePort();
gp.sgpProtocol = line[0];
int num = line.Count();
if (num == 2)
{
gp.sgpPortStart = Convert.ToUInt16(line[1]);
gp.sgpPortEnd = Convert.ToUInt16(line[1]);
}
if (num == 3)
{
gp.sgpPortStart = Convert.ToUInt16(line[1]);
gp.sgpPortEnd = Convert.ToUInt16(line[2]);
}
return gp;
}
Where line is a string array which essentially holds some tokens.
ie.
line[0] = "NAME"
line[1] = "JOHN"
line[2] = "YOUNG"
Now, in a seperate function I have
sGamePortItem pi = new sGamePortItem();
pi.sgpProtocol = "TCP";
pi.sgpPortList.Add(ParsePorts(strCMD));
This gives me a Null Reference Exception, so I changed it to this...
sGamePortItem pi = new sGamePortItem();
pi.sgpProtocol = "TCP";
sGamePort test = new sGamePort();
test = ParsePorts(strCMD);
pi.sgpPortList.Add(test);
Now, the error only occurs on the specified line above.. What am I doing wrong? Is it to do with me using the new keyword incorrectly? Or do I not use 'new'?
Any help would be appreciated as this has been confusing me for a few hours now, lol
Thanks again.
John
Yippee Kai Yai
Signed Polomint.......
|
|
|
|
|
The problem is that your line:
public List<sGamePort> sgpPortList;
should be:
public List<sGamePort> sgpPortList = new List<sGamePort>();
Need to assign a target to sgpPortList before you dereference it, hence the null ref exception.
|
|
|
|
|
Damn, I knew it would be something trivial...
Thanks for waking me up to a silly mistake,
EDIT:
Now I'm getting the error "cannot have instance field initializers in structs"...
Hmmm, this could be a pain...
EDIT AGAIN:
I realised what was wrong.. I hadn't been initialising the sGamePortItem in the list..
sGamePortItem pi = new sGamePortItem();
pi.sgpPortList = new List<sGamePort>();
Thank you for your help, it made me think more about the initialisation...
Yippee Kai Yai
Signed Polomint.......
modified on Thursday, December 3, 2009 2:09 PM
|
|
|
|
|
You need to initialize the list of the struct "sGamePortItem" before assigning the object.
|
|
|
|
|
Hi,
I am developing a web app in VB.NET 1.1. In some Webforms I call a showModalDialog child, but when I close it, the parent session is removed.
Please, how can I hold it?
Thanks in advance,
Jose Alvarez de Lara
|
|
|
|
|
Modal dialogues can't refer to their parent using opener. You need to pass a reference to the parent in the second parameter to showModalDialog.
|
|
|
|
|
Hi Puri,
That is what I did. And I maintain a conversation between then parent and the child.
I am thinking if it is possible to send the parent session to the child and bring it back
to the parent when close the child.
Thanks for your interesting,
Jose
|
|
|
|
|
Hello,
There are two articles here in the Code Project. I am talking about "Those Crazy Popups" and "ASP.Net Modal Window Server Control". I am looking for something like them, but I need to fix those articles into my issue.
Any help will be appreciate.
Regards,
Jose
|
|
|
|
|
Hi,
I have found the answer googling.
It is enough putting
Response.Cache.SetCacheability(HttpCacheability.NoCache)
in the Page_Load of pop up window.
On the other hand here is the code snippet,
Page1.aspx
function DoDo(){
window.showModalDialog("Show.aspx","aa");
}
<asp:linkbutton id="LinkButton1" onclientclick="DoDo()" runat="server">LinkButton
protected void Page_Load(object sender, EventArgs e)
{
Session["AA"] = "have a good day!";
}
Show.aspx
protected void Page_Load(object sender, EventArgs e)
{
if (Session["AA"] != null)
Response.Write(Session["AA"].ToString());
else
Response.Write("NULL..........");
}
I hope this help to other people.
Regards,
Jose
|
|
|
|
|
Hello,
I have folllowing problems on a customized DesignSurface. I Load and save the design in a sort of XAML File (proprietary).
- wenn I copy and Paste a TabControl, Order of TabPages is wrong (reversed). Objects come in the wrong order in the Serialize method of my IDesignerSerializationService implementation.
- Wenn I copy and paste a Context menu, the Paste operation fails for the menuitems. It says "Toolstripmenuitem cant be insert in Container of type Form".
- I Have IExtenderprovider on some controls (ToolStrip). How can I handle that ? wen I Paste, The Design surface searches an object with the same name on the destination surface.
Thanks
|
|
|
|
|
No one knows something ?
|
|
|
|
|
I've been trying to find a webpage containing the syntax of connection strings, especially for Tab, Space, and multiple delimiters. Right now, I am trying to query a text file that is space delimited where I treat consecutive delimiters as one.
The following code snippet is from my connection string in C++ .NET
Extended Properties=\"text;HDR=Yes;FMT=Delimited(' ')\""
Do you know what the syntax should be and where I can find a page with a list of the delimiters with syntax? I have examples for csv format, but have not found other examples on google yet.
|
|
|
|
|
Have you tried www.connectionstrings.com/[^]?
I have not checked for text file connections, but that site has helped me when I can't remember connection string syntax.
|
|
|
|
|
Yes, I already have checked connectionstrings.com. They have examples with Tab, semi-colon, and comma. I have not gotten a space delimiter to work however.
|
|
|
|
|
I want to save variable Values to a file and start another application when unhandled error occurs.
Does anyone has any idea?
Regards Mahdi Ghiasi
|
|
|
|
|
mahdigh wrote: Does anyone has any idea?
About what exactly?
Writing things to a file shouldn't be much of a problem. There's an event[^] that's triggered when an unhandled exception occurs. Starting an application is done via Proces.Start [^].
That about covers it, I guess
I are Troll
|
|
|
|
|
Where is Proces.Start in VB?
Mahdi Ghiasi
|
|
|
|
|
mahdigh wrote: Where is Proces.Start in VB?
In VB.NET you'll find it in the diagnostics namespace.
If you're using VB6, then there won't be a namespace. You'd use the built-in Shell function, or call the CreateProcess [^] API.
Hope this helps
I are Troll
|
|
|
|
|
Where is diagnostics namespace in VB.NET?
Mahdi Ghiasi
|
|
|
|
|
It's under the System namespace. You can call it like this;
System.Diagnostics.Process.Start(@"c:\Them_Variables_Be_Here.txt")
That would open the file in the application that's associated with text-files, which defaults to Notepad. A more elaborate example can be found on MSDN[^].
Enjoy
I are Troll
|
|
|
|
|
Hi,
I am trying to create an application in VB.net which requires the user to enter some information into a form as soon as he unlocks his system, i am able to popup the form as soon as the user unlocks, however it allows the user to access the desktop, can anybody help me to create a form that will allow the user to access the desktop only after closing the form
Thanks for any help in this regards.
|
|
|
|
|
System modal dialogs disappeared with the rise of Windows NT. System-modal only applied to Windows 98 and below.
Let me say it this way. Microsoft removed support for system modal dialogs in Win32. That means they are no longer possible in Windows NT, 2000, XP, Vista, 7, ...
|
|
|
|
|
Hi Dave,
Thanks for ur reply...
If u notice the Windows XP shutdown/logoff dialog, these are modal to the system.
Is there anyway we can replicate this into our applications or maybe an alternative suggestion...
|
|
|
|
|
dileep2009 wrote: If u notice the Windows XP shutdown/logoff dialog, these are modal to the system.
No, they are not. They are dialogs shown on entirely seperate desktops from the one the user normally sees.
dileep2009 wrote: Is there anyway we can replicate this into our applications or maybe an alternative suggestion...
Learn how WindowStations and Desktops work, here[^].
Oh, BTW, there is no support for this stuff native in the .NET Framework. You'll have to P/Invoke all the functions yourself.
|
|
|
|
|
Dave,
Appreciate your help...
i am able to create a new desktop and show a msgbox onto it, however i am unable to show a form in the new desktop, the form is displayed in the original desktop.
below is the code i am using ...
(this is working wonderfully....)
<DllImport("user32.dll")> _
Private Shared Function CreateDesktop(ByVal lpszDesktop As String, ByVal lpszDevice As IntPtr, ByVal pDevmode As IntPtr, ByVal dwFlags As Integer, ByVal dwDesiredAccess As Integer, ByVal lpsa As IntPtr) As IntPtr
End Function
<DllImport("user32.dll")> _
Public Shared Function SetThreadDesktop(ByVal hDesktop As IntPtr) As Boolean
End Function
<DllImport("user32.dll")> _
Public Shared Function GetThreadDesktop(ByVal dwThreadId As Integer) As IntPtr
End Function
<DllImport("kernel32.dll")> _
Public Shared Function GetCurrentThreadId() As Integer
End Function
<DllImport("user32.dll")> _
Public Shared Function SwitchDesktop(ByVal hDesktop As IntPtr) As Boolean
End Function
'desktop
Public Const DESKTOP_CREATEWINDOW As Integer = &H2
Public Const DESKTOP_ENUMERATE As Integer = &H40
Public Const DESKTOP_WRITEOBJECTS As Integer = &H80
Public Const DESKTOP_SWITCHDESKTOP As Integer = &H100
Public Const DESKTOP_CREATEMENU As Integer = &H4
Public Const DESKTOP_HOOKCONTROL As Integer = &H8
Public Const DESKTOP_READOBJECTS As Integer = &H1
Public Const DESKTOP_JOURNALRECORD As Integer = &H10
Public Const DESKTOP_JOURNALPLAYBACK As Integer = &H20
Public Const AccessRights As Integer = DESKTOP_CREATEWINDOW Or DESKTOP_SWITCHDESKTOP
Public Const MB_SERVICE_NOTIFICATION As UInteger = &H200000
Private Sub CreateNewDesktop()
'Get the current desktop
Dim _hOrigDesktop As IntPtr = GetThreadDesktop(GetCurrentThreadId())
'create our desktop
Dim _hNewDesktop As IntPtr = CreateDesktop("MyDesktop", IntPtr.Zero, IntPtr.Zero, 0, AccessRights, IntPtr.Zero)
' set the thread desktop
SetThreadDesktop(_hNewDesktop)
SwitchDesktop(_hNewDesktop)
'MessageBox.Show("test", "test", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.ServiceNotification)
Form2.showdialog() 'this is not shown in the new desktop
SwitchDesktop(_hOrigDesktop)
SetThreadDesktop(_hOrigDesktop)
End Sub
is there something i am missing out...Also is there a way to get all the processes in the original desktop to the new desktop just to imitate the original one..
|
|
|
|