|
Cool, thanks Mika
|
|
|
|
|
No problem Hopefully others will share their opinions too.
|
|
|
|
|
Due to a recent hard to find problem with this same scenario, I switched to using properties exclusively for setting variable values (per recommendation of Dave K).
It's a couple more lines of code and very minimal time to just break it out. Even if your code for now doesn't have any extra checks/logic before setting the value and it's module/class scope, you could easily expand the property to add checks in the future. It also helps in determining when a variable gets a value that is not expected.
In VB6, you could create and set a global breakpoint to "break" when the variable is set = to the value your looking for. That type of global break point doesn't exist in VB.Net. If your variable is set using a property, then you can indeed easily do this without breakpointing everywhere the variable is being set.
As you mentioned, you can have mix match of scope within the property itself.
Performance wise, unless your doing something off the wall like a trillion loops with reading/setting values, you are not going to have a performance issue; otherwise, you might want to access the variable directly in these rarer cases (like Mike discussed).
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
OK, thanks Jon_Boy. Like Mika suggested, this sounds like a matter of coding style, but I do actually like the idea of using properties to set object wide variables. After all, I use properties to set some variables but then directly assign others, so using properties to set all variables will at least ensure consistency, which I like.
Thanks for your time
|
|
|
|
|
The reason I told him that little trick is because occasionally you run into a problem where a value is set in a class, but you can't find where the value is being set from. Using a private property, you can set a breakpoint in the setter code, then look at the stack trace to see exactly where the value came from.
|
|
|
|
|
I did try to search (albeit quick) for my orig post yesterday, but couldn't find it. oh well...
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Hi I'm stuck on this problem I have with the webbrowser control. I am trying to print a html doc that has been loaded into the control like follows
html.Navigate(New System.Uri(fileName))
html.Show()
html.Width = 800
html.Height = 600
html.Refresh()
and then print it using
html.print
but nothing happens. Does anyone know why
Stephen Lintott Bsc IT (RAU)
|
|
|
|
|
Stephen Lintott wrote: but nothing happens. Does anyone know why
Do you have a printer configured?
print() function takes the default page and print settings form the system.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Yes sorry should have said it but I do have a printer configured.
Stephen Lintott Bsc IT (RAU)
|
|
|
|
|
try html.Print()
with the parenthesis, also check your default printer...
See the documentation[^] for information about permissions.
|
|
|
|
|
hello to everyone
I'm trying to store an ID of a person from a table which is related to another so I wrote a peace of code that takes the names of persons from that table and expandes them on a combobox but when I click on a Save button it does not take the ID of a person to store it on a table which is related.
Here is my code:
Private Sub frmXhirojare_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ds As New DataSet
Dim conn As SqlConnection = New SqlConnection("Data Source=.;Initial Catalog=dbHyrjaXhirove;Integrated Security=True")
Dim selection As String = "SELECT PartneriID, Emri FROM tblPartneret"
Dim dataadapteri As SqlDataAdapter = New SqlDataAdapter(selection, conn)
dataadapteri.MissingSchemaAction = MissingSchemaAction.AddWithKey
dataadapteri.Fill(ds, "tblXhiro")
ComboBox1.DataSource = ds.Tables("tblXhiro")
ComboBox1.ValueMember = "PartneriID"
ComboBox1.DisplayMember = "Emri"
End Sub
I would be thankful to everyone who takes a minute from his time to explain it to me why when I click to the Save button it does not take the PartneriID in this case and store it on related table.
Qendro
|
|
|
|
|
ComboBox1.Value should contain the person Id.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
Could You be more specific and tell me where to write Combobox1.Value because in my code I wrote Combobox1.ValueMember = "PartneriID" which I think is the appropriate thing in this case.My problem is that when I click on the Save button it saves all the values through the parameters exept the PersoniID which is represeted by this combobox.
Thank You for your reply and I would be thankful if You put me in a correct road with this problem.
Qendro
|
|
|
|
|
ValueMember sets where to get the value from. Value is the value that was set. I think you need to do some reading on VB.NET, this is pretty straightforward stuff.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
|
|
Thanks Mika. But how do I code to insert the new line below Address1 each time?
|
|
|
|
|
For example, loop the array read from the file and insert each element to another array. Also in the loop, check if the string is Address1 and if it is, after insertion to the target array add an extra element for the url (or whatever you wish to add).
If you know the amount of Address1 elements, you can define the target array size before the loop. For example target array length + target array length / 3 (if you always have 3 rows for each person). If you cannot calculate the size beforehand, you can use Array.Resize[^] when needed
|
|
|
|
|
This should be a relatively easy thing to do. If your still stuck, post the code that you have so that we can see what your doing.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
This is the code I am using; the result is that the insert is placed only in the last line of the text file (not immediately after all occurences of "CBS*TODAY*ZZ*" like I need it to).
Private Sub btnTranslate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTranslate.Click<br />
MessageBox.Show("you are about to translate file")<br />
<br />
'read the file to find data<br />
Dim sReader As New IO.StreamReader("C:\shadow\moviez_21.txt")<br />
Dim CurrentLine As String<br />
<br />
Dim DataLines As New System.Collections.Specialized.StringCollection<br />
<br />
CurrentLine = sReader.ReadLine<br />
If CurrentLine.StartsWith("CBS*TODAY*ZZ*") = True Then<br />
sReader.ReadToEnd()<br />
End If<br />
sReader.Close()<br />
<br />
'modifying the file<br />
Dim oError As System.IO.StreamWriter<br />
oError = New System.IO.StreamWriter("c:\Shadow\moviez_21.txt", True)<br />
<br />
'text to be inserted always after CBS*TODAY*ZZ*<br />
oError.Write("REF*LU*") ' + file number<br />
oError.Close()<br />
End Sub
Thanks
|
|
|
|
|
Can you explain how you were thinking when writing this? It's not even close to working...
IvanIT wrote: CurrentLine = sReader.ReadLine
If CurrentLine.StartsWith("CBS*TODAY*ZZ*") = True Then
sReader.ReadToEnd()
End If
Here you only read the first line of the file and throw away the rest. Then you just forget about the line that you read, because you never use that for anything.
The comment earlier in the code suggests that you attempt to find a line in the file, but you don't have any loop so the only line that you ever look at is the first one.
IvanIT wrote: oError = New System.IO.StreamWriter("c:\Shadow\moviez_21.txt", True)
Here you open the file for appending, that means that you contine to write at the end of the file.
IvanIT wrote: 'text to be inserted always after CBS*TODAY*ZZ*
oError.Write("REF*LU*") ' + file number
The comment doesn't at all correspond to what you are actually doing. You are writing that string at the end of the file, regardless if you found the string that you were looking for or not.
All the code that you have written could be replaced with just this:
Private Sub btnTranslate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTranslate.Click
MessageBox.Show("you are about to translate file")
System.IO.File.AppendAllText("c:\Shadow\moviez_21.txt", "REF*LU*")
End Sub
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I am actually in a better place now with the code below. But here comes my problems:
1. the FileName will change from time to time
2. the myString will always StartsWith SOM*PE*ZZ*, but the last 4 digits will change. How do I make that variable?
Like I said, I have been testing the code below and except for the above 2 issues, its smooth sailing. I would greatly appreciate input in making the tweaks.
Imports System<br />
Imports System.Text<br />
Imports System.Windows.Forms<br />
<br />
Private Sub btnTranslate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTranslate.Click<br />
<br />
MessageBox.Show("you are about to translate file")<br />
MessageBox.Show("you are about to translate file")<br />
<br />
Dim refNum As String = Me.txtFileNum.Text<br />
Dim FileName As String = "C:\moviez_21.txt"<br />
Dim myString As String = "SOM*PE*ZZ*1041"<br />
<br />
Dim newString As New StringBuilder<br />
newString.Append(My.Computer.FileSystem.ReadAllText(FileName))<br />
newString.Replace(myString, myString & vbNewLine & "TODAY*007*" & refNum & "~")<br />
My.Computer.FileSystem.WriteAllText(FileName, newString.ToString, False)End Sub
|
|
|
|
|
Hm... why are you using a StringBuilder when you are not building a string?
You can use a regular expression to match the line and do the replacement. How about a one-liner:
File.WriteAllText(fileName, Regex.Replace(File.ReadAllText(fileName), "(SOM\*PE\*ZZ\*\d{4})", "$1" + Environment.NewLine + "TODAY*007*" + refNum.ToString() + "~"))
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Read line the lines using ReadAllLines, then open a StreamWriter on the file and write each line. When you come to the place where you want to add the line, just write it to the StreamWriter.
Despite everything, the person most likely to be fooling you next is yourself.
modified on Monday, January 26, 2009 12:51 PM
|
|
|
|
|
Hi All,
I am trying to dev a small application with login form, but i am not able to unload login form after confirming the user id and password.
Any help will be appreciated.
Thanks in advance.
Regards.
Zanzmera
|
|
|
|