|
I'd create a class that builds the menus programatically from scratch & add call that class from the form. I'd use a function in the class to build the menus according to the logged on users department. The information regarding departments would be held separately in a datasource of some kind. I may even add values to the datasource to control menu item properties on the fly.
But that's just me. Your project may require something different.
|
|
|
|
|
I gt a line of data which i intend to display in CSV file as below,
"A12435625" "b" "b2" "c44566"
"A12435625" "b" "b2" "c44566"
however with my coding, it only displayed as
"A12435625" "b" "b2" "c44566" "A12435625" "b" "b2" "c44566"
What is my mistake and how to display my desire answer? Below is my coding, pls kindly help!
FileOpen(2, sFilename, OpenMode.Output)
For b = 0 To CreatePP.Counter - 1
For a = 0 To 4
c = CStr(CreatePP.Data(a))
If c.Length <= 1 Then
c = c.PadRight(2, CChar(" "))
ElseIf c.Length <= 2 Then
c = c.PadRight(3, CChar(" "))
ElseIf c.Length > 2 And c.Length <= 4 Then
c = c.PadRight(5, CChar(" "))
ElseIf c.Length > 4 And c.Length <= 6 Then
c = c.PadRight(7, CChar(" "))
ElseIf c.Length > 6 And c.Length <= 11 Then
c = c.PadRight(12, CChar(" "))
End If
Write(2, c)
Next a
Next b
FileClose(2)
-- modified at 0:27 Thursday 12th October, 2006
|
|
|
|
|
I think if you add either vbCrLf or ControlChars.NewLine to where you want the string to be written on a new line that may work.
|
|
|
|
|
Thanx for help although it didn't work. As a result,it ony return
"aaaaaaaa",blank line,"b",blank line,"b2". Do you have another tricks or idea?
|
|
|
|
|
We need to see your code so we can figure out what you did wrong.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
It is almost the same,i highlighted the change the below.
I gt a line of data which i intend to display in CSV file as below,
"A12435625" "b" "b2" "c44566"
"A12435625" "b" "b2" "c44566"
however with my coding, it only displayed as
"A12435625" "b" "b2" "c44566" "A12435625" "b" "b2" "c44566"
What is my mistake and how to display my desire answer? Below is my coding, pls kindly help!
FileOpen(2, sFilename, OpenMode.Output)
For b = 0 To CreatePP.Counter - 1
For a = 0 To 4
c = CStr(CreatePP.Data(a))
If c.Length <= 1 Then
c = c.PadRight(2, CChar(" "))
ElseIf c.Length <= 2 Then
c = c.PadRight(3, CChar(" "))
ElseIf c.Length > 2 And c.Length <= 4 Then
c = c.PadRight(5, CChar(" "))
ElseIf c.Length > 4 And c.Length <= 6 Then
c = c.PadRight(7, CChar(" "))
ElseIf c.Length > 6 And c.Length <= 11 Then
c = c.PadRight(12, CChar(" "))
End If
Write(2, c) Write(2,c,ControlChars.Newline)
<br />
<br />
Next a<br />
<br />
Next b<br />
<br />
FileClose(2)<br />
<br />
I appreciate so much for help!Thanx!
|
|
|
|
|
First, copy and paste your ACTUAL code, not something that's "alomst the same". I very small difference in your code can make all the difference in your output.
Next, don't use ControlChars.NewLine. If you want a complete new line, which is TWO characters in Windows (CR and LF), use Environment.NewLine instead.
TeiUKei wrote: If c.Length <= 1 Then
c = c.PadRight(2, CChar(" "))
ElseIf c.Length <= 2 Then
c = c.PadRight(3, CChar(" "))
ElseIf c.Length > 2 And c.Length <= 4 Then
c = c.PadRight(5, CChar(" "))
ElseIf c.Length > 4 And c.Length <= 6 Then
c = c.PadRight(7, CChar(" "))
ElseIf c.Length > 6 And c.Length <= 11 Then
c = c.PadRight(12, CChar(" "))
End If
What on earth is this doing?? You realize that c is being evaluated for length in every one of those if statements, including after each new change you make by padding it with spaces?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Well, this is the actual code i am doing. I still can't find where the problem is although i use Environment.Newline, sorry for the troublesome!
This is the data i try to displayed
Dim Data1 As New PropertyCreateFile
Dim aa As New ArrayList
aa.Add("A4585525581")
aa.Add("b")
aa.Add("b2")
aa.Add("c234")
aa.Add("M45686")
Data1.Data = aa
Data1.Counter = 3
'aaa.CreateTextFile(Data1)
aaa.CreateCSVFile(Data1)
Public Function CreateCSVFile(ByVal CreatePP As PropertyCreateFile) As String
Dim sFilename As String = (CurDir & "/CSVFile.csv")
Dim b As Integer
Dim a As Integer
Dim c As String
Dim Data(4) As String
FileOpen(20, sFilename, OpenMode.Output)
For b = 0 To CreatePP.Counter - 1
For a = 0 To 4
c = CStr(CreatePP.Data(a))
'For these if statement, i intend to get and check the
'length of data pass in by user, so the data can displayed
'systematically
If c.Length <= 1 Then
c = c.PadRight(2, CChar(" "))
ElseIf c.Length <= 2 Then
c = c.PadRight(3, CChar(" "))
ElseIf c.Length > 2 And c.Length <= 4 Then
c = c.PadRight(5, CChar(" "))
ElseIf c.Length > 4 And c.Length <= 6 Then
c = c.PadRight(7, CChar(" "))
ElseIf c.Length > 6 And c.Length <= 11 Then
c = c.PadRight(12, CChar(" "))
End If
Data(a) = c
'Is it right if i use Environment.NewLine here?
Write(20, Data(a), Environment.NewLine)
Next a
Next b
FileClose(20)
|
|
|
|
|
This is not all the code that's involved.
What's the code for PropertyCreateFile and what is it supposed to do?
Where is aaa defined ("aaa.CreateCSVFile(Data1) "), and as what?
If c.Length <= 1 Then
c = c.PadRight(2, CChar(" "))
ElseIf c.Length <= 2 Then
c = c.PadRight(3, CChar(" "))
ElseIf c.Length > 2 And c.Length <= 4 Then
c = c.PadRight(5, CChar(" "))
ElseIf c.Length > 4 And c.Length <= 6 Then
c = c.PadRight(7, CChar(" "))
ElseIf c.Length > 6 And c.Length <= 11 Then
c = c.PadRight(12, CChar(" "))
A CSV file doesn't care about padding, so what's this for? Is this for displaying the information in a TextBox or something, while you write the data to a CSV file?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Really? So, how about when it convert to text file?
Anyway,this is where aaa defined which you ask about.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Data1 As New PropertyCreateFile
Dim aa As New ArrayList
aa.Add("A45855")
aa.Add("b")
aa.Add("120306")
aa.Add("c234")
aa.Add("M45686")
Data1.Data = aa
Data1.Counter = 3
aaa.CreateCSVFile(Data1)
End Sub
'This is the code for PropertyCreateFile. It will take in the data detail and 'counter on how many times it will loop.
Public Class PropertyCreateFile
Dim Str As ArrayList
Dim Ctr As Integer
Dim UBSBadgeNo As Integer
Public Property Data() As ArrayList
Get
Return Str
End Get
Set(ByVal Value As ArrayList)
Str = Value
End Set
End Property
Public Property Counter() As Integer
Get
Return Ctr
End Get
Set(ByVal Value As Integer)
Ctr = Value
End Set
End Property
End Class
Public Function CreateCSVFile(ByVal CreatePP As PropertyCreateFile) As String
Dim sFilename As String = (CurDir & "/CSVFile.csv")
Dim b As Integer
Dim a As Integer
Dim c As String
Dim x As String
Dim Data(4) As String
FileOpen(20, sFilename, OpenMode.Output)
For b = 0 To CreatePP.Counter - 1
For a = 0 To 4
c = CStr(CreatePP.Data(a))
If c.Length <= 1 Then
c = c.PadRight(2, CChar(" "))
ElseIf c.Length <= 2 Then
c = c.PadRight(3, CChar(" "))
ElseIf c.Length > 2 And c.Length <= 4 Then
c = c.PadRight(5, CChar(" "))
ElseIf c.Length > 4 And c.Length <= 6 Then
c = c.PadRight(7, CChar(" "))
ElseIf c.Length > 6 And c.Length <= 11 Then
c = c.PadRight(12, CChar(" "))
End If
Data(a) = c
Next a
x = Data(0) + Data(1) + Data(2) + Data(3) + Data(4)
WriteLine(20, x, Environment.NewLine)
Next b
FileClose(20)
Return Nothing
End Function
Thanks for help, Dave!!
|
|
|
|
|
TeiUKei wrote: Really? So, how about when it convert to text file?
A CSV file (Comma Seperated Values) IS a text file!
TeiUKei wrote: WriteLine(20, x, Environment.NewLine)
Change it to this:
WriteLine(20, x)
WriteLine(20, Environment.NewLine)
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hello
I have to create some reports. I have been told to use typed dataset as this is the best way for deployment.
I am using visual basic 2005, sql 2005 and crystal report 10
Does any one know of any good tutorials that tell you clearly how to do this. This is my first time.
Thanks in advance,
Steve
|
|
|
|
|
You should be asking this in the SQL Forum, not VB.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hey,
I was looking through REGEDIT and I found a 2 different startup keys. Some programs used the: HKEY_CURRENT_USER/Software/Microsoft/Windows/Current Version/Run and most use the: HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/Current Version/Run . Is there a difference between which one you put your startup key in?
Thank you!
|
|
|
|
|
The _CURRENT_USER is only run for a specific user when they log on, the _LOCAL_MACHINE one runs every time anyone logs on.
|
|
|
|
|
Why didn't I think of that? Thanks!
|
|
|
|
|
Hi,
How can you change the screensaver through the registry? I've found the generic Windows screensavers, but not a custom one. Where might that be?
Thank you!
|
|
|
|
|
It's the same setting. There is special location to specify a custom screen saver.
HKEY_CURRENT_USER\Control Panel\Desktop
Look for the SCRNSAVE.EXE value. This specifies the filepath of the screen saver for the current user.
The location for the screen saver when noone is logged in is under
HKEY_USERS\.DEFAULT\Control Panel\Desktop
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
|
Does anybody have any ideas why, if I add a field to a table in MS Access, and then run the data adapter configuration wizard on the dataset already in place in VB.NET (to 'capture' the new field), it refuses to generate an UPDATE or a DELETE statement, but if I remove the field in Access, and then re-run the wizard in Visual Studio, it goes through ok.
It doesn't seem to matter what I call the field, or what data type I am using, it always gives the same error ('There were errors configuring the data adapter') only on the UPDATE and DELETE statements (SELECT, Mapping, and INSERT are fine).
For info, I've got a parent and child table (tblSupplierProductsParent and tblSupplierProductsChild). The relationship is a one-to-many link between fields called 'ProductIDNumber' and 'ProductID' in the parent and child tables respectively. I had initially assumed that there was a problem with the relationship, but its fine if I don't add an extra field to the parent table.
I've temporarily deleted the relationship in Access and tried it again on a new form in VB.NET - with the extra field gives the problem, but without the extra field its fine.
I've never come across anything like this before, and I'm completely confused why it should behave so weird! Help!!!
|
|
|
|
|
I've had a similiar problem in the past. I'm not sure of the cause but what worked for me was refreshing the connection in server explorer & then reconfiguring the data adapter.
I think it doesn't recognize the field in the server explorer copy of the table until you refresh the connection and the extra field shows up as part of the table. Hence it can't automatically generate update & delete statements as the table structure has been changed & is unknown.
Then again, I'm probably wrong.
|
|
|
|
|
Thanks - this seems to have solved it. Very odd.
|
|
|
|
|
Hey,
I'm trying to write a program that views pictures and using left/right buttons, allows you to view the next/previous image in a folder of many other images. Well, I'm also using a hidden File List Box to browse through the pictures, but, without clicking on the next file in the List Box, how do I select the next file?
I hope this isn't too confusing! Please let me know.
|
|
|
|
|
If the FileListBox is hidden, why are you even using it? You'd have an easier time just getting the list of files on your own and managing the collection. Then there's nothing to "click on", (in a hidden control, why would you even want to?).
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Ok, how do I go about listing and managing the files?
|
|
|
|
|