Jump to content
Xtreme .Net Talk

Wentu

Members
  • Posts

    7
  • Joined

  • Last visited

Personal Information

  • .NET Preferred Language
    C#, VB

Wentu's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. ********** You could solve this in 2 ways off the top of my head: 1. Have the child form S expose a bool value that form F reads. 2. Wrap your bool value in a class and pass the class to the constructor of S. ********** Thankx a Lot Nerseus Actually i was already using what u call Solution #2 but i though of it as a rather unelegant solution and trying to understand why my previous solution wasnt working. i think Solution1 is against incapsulation... Thankx for the explanations and suggestions! ;) Wentu
  2. Thanx Nerseus for ur answer. i am sorry i wrote in a cryptic way. What i imagined it happend was: A is an object, that is , a pointer to an object, but when i write dim A as Object = new boolean it points to enough memory for a boolean. The same is true for B. I pass to the function scegli the pointer B, and inside the function it is called in another way, who cares, it is always pointing to the same location of memory. When I write A = buleano i say: let A point to the same location where buleano points, that is, the same location where B is pointing (where i am storing a boolean). Now, i think the problem is here: if i write A = true i thought i was changing the value IN the memory location pointed by A, not the place where A is pointing. A is pointing where a boolean is stored, how can i change the boolean itself and not where A is pointing ?? Anyways... (and sorry for the awful crossposting): Here's what i was trying to do: I am working in NET CE and i have 2 forms, F (father) and S (son). F instantiates S and show it with ShowDialog(). In the constructor S i pass a boolean byRef, in S i can check or not a checkbox and depending on this check, i want the ByRef variable to change and be seen in F. So: In F: dim myBool as Object = new boolean dim newS as S(myBool) if myBool then doSomthing() else doSomethingElse() end if ----- in S private prBoolean as Object = new Boolean public sub new (ByRef aBool as Obj) prBoolean = aBool end sub Private Sub newS_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing If Me.myCombo.Checked = True Then prBoolean = False Else prBoolean = True End If End sub ---------------------------- now, when i set prBoolean = true , I was expecting that aBool and myBool all changed to True. I thought all of the 3 objects point to the same location and writing prBoolean = True changes the content of what is pointed, not the location to which prBoolean points. prBoolean is an Object, how do i tell to prBoolean to change NOT WHERE it's pointing but the boolean value it is keeping ?? thankx a lot again
  3. Hi I am trying to understand the behaviour of boxing. here's the code, don't take into account the fact that is in a form: Dim A As Object = New Boolean Dim B As Object = New Boolean Dim mB As mioBool = New mioBool Dim C As mioBool = New mioBool Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load B = False mB.thisBool = False scegli(B) scegliBool(mB) End Sub Private Sub scegli(ByRef buleano As Object) A = buleano A = True End Sub Private Sub scegliBool(ByRef aMioBool As mioBool) C = aMioBool C.thisBool = True End Sub ************* when scegliBool is called, C points to the same object as mB, so when i change the boolean in C, also the boolean in mB changes. That's great. BUT, when i call scegli, i was expecting A to point to the same boxed boolean as B, and when i set A to TRUE, i thought B also would have changed to True, but this is not the case. Why ? how can i change the value of B acting only on the A object, how can i have B and A pointing to the same object and behaving in the same way ? Thankx Wentu
  4. Hi ! I need to access the HTML content of a page. I know how to do this if the page is public but now i want to access a page that is in a site that requires previous authentication. What i usually do is going to the login page, write my usernames and password and then submit, and then i have access to http://www.AddressOfThePageIWantToRead.asp . In the login page there is a form whose action is http://www.AddressOfThePageIWantToRead.asp and method = POST . The names of the textboxes where i write are "username" and "password". I'd like to be able to give my username and pwd and write in a string (lcHtml) the content of http://www.AddressOfThePageIWantToRead.asp . I found something on the net, that is: Dim lcUrl As String = "http://www.AddressOfThePageIWantToRead.asp" Dim loHttp As HttpWebRequest = WebRequest.Create(lcUrl) Dim lcPostData As String = "Username=" & HttpUtility.UrlEncode("MyUsername") & "&Password=" + HttpUtility.UrlEncode("MyPWD") loHttp.Method = "POST" Dim lbPostBuffer As Byte() = System.Text.Encoding.GetEncoding(1252).GetBytes(lcPostData) loHttp.ContentLength = lbPostBuffer.Length Dim loPostData As Stream = loHttp.GetRequestStream() loPostData.Write(lbPostBuffer, 0, lbPostBuffer.Length) loPostData.Close() Dim loWebResponse As HttpWebResponse = loHttp.GetResponse() Dim enc As Encoding = System.Text.Encoding.GetEncoding(1252) Dim loResponseStream As StreamReader = New StreamReader(loWebResponse.GetResponseStream(), enc) Dim lcHtml As String = loResponseStream.ReadToEnd() loWebResponse.Close() loResponseStream.Close() the site is actually responding with a page that says : Username and/or pwd uncorrect. Of course i know my username and pwd ARE correct. so what could be the problem ? the encoding of UrlEncode ? what else ? what am i missing ? if the complete answer is too long, at least tell me where to find a good tutorial or illuminating post, please ! thanx ! Wentu
  5. 1st of all thankx for the reply you should try: cmds(i).Open() cmds(i).ExecuteScalar cmds(i).Close() as i said, the connection is opened outside the function and is global. then, i can't even see how to open a Command. if i write "cmds(i)." it does not shows the open method I'm also curious as to why you are using arraylist of command object instances, why not just create new instances as they are needed? i read an article that says i must do that: having a command object for every query i often use, so that i can prepare it and use it every time i want, in different places. If performance is your primary concern, I would recommend using a pool of connection objects and allocating them as needed, instead of bothering with the collection of command objects. SQLCE allows, afaik, only 1 connection at a time so far, the only solution i found is to specify the SQLCEType of parameter and set it every time to a NVarChar. in this case, it works. I found out that the problem was a sort of invalid cast when i set the value of the parameter the second time. Wentu
  6. Hi all i have a function paramQuery that, given an integer i and an Object param, returns the result of a scalar query from a SqlCEConnection gConn. I store all my possible queries in an array SELECTsqlstrs and all my commands in an array cmds. Depending on the passed i, I know which command excecute. If the command does not exists, i build it, otherwise i just invoke it. Well, the first time i call the function with a given i, it works, but at the second time, it throws an exception (SqlServerCE.SqlCEException) I think i am not allowed to close the gConn but i suspect i need to .close() something else... could u tell me where's the problem ? I am working on a PocketPC appl, with WinCE. All the queries return a scalar and have only one parameter. che gConn is global. thankx Wentu ****************************************** If cmds(i) Is Nothing Then cmds(i) = gConn.CreateCommand cmds(i).CommandText = SELECTsqlstrs(i) Dim p As SqlCeParameter = New SqlCeParameter cmds(i).Parameters.Add("Par1", param) cmds(i).Prepare() Else cmds(i).Parameters(0).Value = param End If paramQuery = cmds(i).ExecuteScalar
  7. Hi ! here's a real pain in the RegEx that is taunting me in some way. What i need is, convert this couple of line (written here in their general form): Me.VARIABLENAME.Location = New System.Drawing.Point(COORDINATEX, COORDINATEY) *****zero or more possible other lines of code like "Me.VARIABLENAME.SOMETHINGELSE...BLABLABLA" Me.VARIABLENAME.Size = New System.Drawing.Size(WIDTH, HEIGHT) in something like Me.VARIABLENAME.Bounds = New System.Drawing.Rectangle(COORDINATEX, COORDINATEY,WIDTH, HEIGHT) I use the regex of .NET framework and the replace function. The Regex i found is: Me\.([a-zA-Z_][_a-zA-Z0-9]*)\.Location = New System\.Drawing\.Point\(([^,]+,[^,]+)\)((.*\n)*)[ \t]*Me\.\1\.Size = New System\.Drawing\.Size\(([^,]+,[^,]+)\) and the possible replacement is: Me.$1.Bounds = New System.Drawing.Rectangle($2,$5)$3 it almost always works, with 0 or more lines in the middle. Notice that $3 should put all that is inside the two lines, immediately after the last parenthesis in the resulting string. It happens, rarely, something like this: the $3 is placed randomly after a certain number of line, like in the following examlple: *************************************** ' 'dgIncassi ' Me.dgIncassi.Location = New System.Drawing.Point(0, 26) Me.dgIncassi.Size = New System.Drawing.Size(238, 220) ' 'TB ' Me.TB.Buttons.Add(Me.tbCmdExit) Me.TB.ImageList = Me.IM ' 'tbCmdExit ' Me.tbCmdExit.ImageIndex = 0 ' 'IM ' Me.IM.Images.Add(CType(resources.GetObject("resource"), System.Drawing.Image)) Me.IM.ImageSize = New System.Drawing.Size(16, 16) ' ************************************ is converted in: ************************************ ' 'dgIncassi ' Me.dgIncassi.Bounds = New System.Drawing.Rectangle(0, 26,238, 220) ' 'TB ' Me.TB.Buttons.Add(Me.tbCmdExit) Me.TB.ImageList = Me.IM ' 'tbCmdExit ' Me.tbCmdExit.ImageIndex = 0 ' 'IM ' Me.IM.Images.Add(CType(resources.GetObject("resource") , System.Drawing.Image)) Me.IM.ImageSize = New System.Drawing.Size(16, 16) ' ********************************** what is amazing is that in this case $3 is a carriage return and it is placed in the line beginning with Me.IM.Images.Add The string ", System.Drawing.Image))" comes out actually in a new line but it should follow the line before. Since this is VB.nET code, i can't afford a carriage return !! Could anyone explain me why in this particular case the $3 is placed not immediately at the end of the regex but some lines later ?? Thankx so much !! Wentu
×
×
  • Create New...