|
Maybe what you want is a Panel (or PictureBox), then you can paint/see exactly what you
want; the events would be slightly different of course.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I'm using a streamwriter to output 4 columns of data into a text file. Unfortunately the columns aren't lining up correctly. I've tried using Controlchars.tab & vbTab which do not work. Is there any way to create tabs in the writeline method or would I need to switch to a rich text file for this?
If anyone can help it would be greatly appreciated! Oh yeah I'm using Visual Basic 2003.
Swish
|
|
|
|
|
Where don't they line up ? Tabs only line up if your strings are similar lengths, a long one will skip several tab stops.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Horizontal alignment is bound to fail unless one of two conditions is met:
- all characters have the same width, i.e. the font is non-proportional such as "Courier New";
- you take into account the exact width of each character
On top of that, a TAB character most of the time indicates jumping to the next multiple
of 8 (or 4 or whatever) character positions, again assuming a non-proportional font.
[added]And not: moving to the next column, as would be the case in Word or Excel table[/added]
-- modified at 20:57 Tuesday 9th October, 2007
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
What you're describing is a report text file, not a tab delimited file.
A delimiter is a character or string of characters that seperates fields in a data file. What you're describing is a text file laid out like a report.
|
|
|
|
|
Thanks guy's for replying. The alignment is thrown off by the strings length. And right now padding is still throwing off the alignment. I'm using "Arial" with a font size of "8" and pagesettings.landscape = True.
Dave your right, but I'm having trouble with the layout of the report. Is there a better method of creating reports that have correct alignment in a text, rtf or doc file? Or have the app write to a specific location within the file to better align the report?
Swish
|
|
|
|
|
You have two problems. The first is that different application interpret tabs differently. One may replace a tab character with a bunch of spaces and another might add a bunch of whitespace to hit the next tabstop in it's rendering engine, while another might do something different and add a different amount of whitespace for each tab.
The second is that Arial is a proportional font, meaning that each character is rendered in a cell reletive to the size width of the character. Spaces can be very narrow compared to all the captial letters. Mono-spaced fonts have every character, even spaces, rendered in cells of the exact same width for every character. This means that a space is exactly the same width as, say, a captial W.
If you're writing to a text file (*.TXT), the font doesn't matter since it's not used in the file. What screws up the formatting is the application that is rendering the text. For instance, if you open the file in Notepad and configure Notepad to use the Arial font, the report layout will be severly messed up. Change the font Notepad uses to something like Lucida Console, which is mono-spaced, and column alignment changes.
But now you have a problem with the size of the columns. Assume that you have two lines of text int the file, laid out like this:
sometext[TAB]some more text
someotherlongertext[TAB]even more text
Say Notepad uses a tabstop every one inch. The "sometext" in the first line of the file is shorter than than one inch. The tab will move the cursor to the one mark and then the rest of the line shows up.
Now, for the second line, the first part of it, "someotherlongertext", is longer one inch. Well, the tab will move the cursor to the two inch mark, where the rest of the line will be rendered. And if you haven't figured it out yet, the second column will not be lined up.
There-in lies the problem with using Tabs to do reporting. Each line will have to know how it's going to be rendered and have a variable number of tabs between columns to line them up. Since your application can't possibly know how the text file is going to be rendered, it's impossible to predict the number of tabs needed between columns for each line in the report.
What's the solution?? Use a dedicated reporting tool, like CrystalReports, to generate the report.
If it has to be in a text file, replace the tabs with a known number of spaces. You're going to have to do more work like keeping track of how many characters are in each field and how wide (in characters) each field can hold. Then you can calculate the number of spaces you need to add between those two fields to get them to line up.
Even then, use a proportional font to show the text and the spaces won't even line the columns up.
|
|
|
|
|
Thanks Dave for taking the time to explain. Though I've never worked with Crystal Reports I'm going to give it a try. Thanks!;)
Swish
|
|
|
|
|
example:
suppose i have 3 forms
and sequence of opening is form1->form2->form3
form1 is MDi parent, form3 is MDi child
on clickin of form1, form2 gets open which takes some values from user retreives the data and accordingly opens form 3..
ma doubt is from form1, form2 can b made mdi child
but from form 2, how form3 will b made child of form1..???
thanks
|
|
|
|
|
From form2 use the following
Dim form As New Form3
form.MdiParent = Me.MdiParent
form.Show()
</code>
-- modified at 21:24 Tuesday 9th October, 2007
Mike Lasseter
|
|
|
|
|
its not working man...
form3 is not becoming child of form1..
|
|
|
|
|
Yes it does work. The code I pasted should be run on form2. Paste you code for each form and I will tell you what you are doing wrong.
Mike Lasseter
|
|
|
|
|
i am using VS 2005.
when i am writin this code in button click event of form2,
form 3 gets open but not as a child of form1..
it opens as individual form...
|
|
|
|
|
The code I posted works, post your code for each form.
Mike Lasseter
|
|
|
|
|
form1 is mdiparent with ismdicontainer as true
coding for form1
button_click event<br />
dim frm2 as new form2<br />
frm2.show()<br />
now in button click event in form2
<br />
dim frm3 as form3<br />
frm3.mdiparent=me.mdiparent<br />
frm3.show()<br />
this was your method..
the method which i am using is in form2 i code
button_click()<br />
dim frm3 as new form3<br />
frm3.mdiparent= form1<br />
frm3.show()<br />
this one works but only when form1 is startup form.
if form1 is any intermediate form and startup form is any other form then this method doesnt works..
any solution..??
thanks
|
|
|
|
|
You are right, I misread your post and thought Form2 was an MdiChild of Form1 as well.
I don't understand why you would ever use the scenario in your post. Generally, with Mdi applications you don't create forms that are not MdiChildren or Dialog forms (dialog forms must be closed before you can do anything else in the application, like the MessageBox). The reason for this is all your forms are neatly contained in the main application instead of spread out across your machine. But you know what you are trying to do better than me, just hope I was able to offer something helpful.
Mike Lasseter
|
|
|
|
|
I want to create a tab dynamically and put a browser control in it.
BiG RaLpH
|
|
|
|
|
Dim newPage as New TabPage()
newPage.Controls.Add(New WebBrowser())
yourTabControl.TabPages.Add(newPage)
That's about the simplest form of it.
The early bird who catches the worm works for someone who comes in late and owns the worm farm. -- Travis McGee
|
|
|
|
|
now how can I access it?
BiG RaLpH
|
|
|
|
|
there a few possible ways:
1) declare the control you want to access global (dim w as webbrowser)
when you create it you first need to initialize it ( w = new webbrowser)
this way you can access the control from anywhere (always check first if it has been initialized ( if w isnot nothing then 'do you're code))
2) when you create the control give it a unique name (w.name = "unique")
then when you want to access it you can just run true the controls on you tabcontrol (normally all tabpages) and for each tabpage run true his controls and compare name
(if control.name.tolower.equals("unique") then ' do you're code)
this is a bit more work and I think it's better to use the first option (for performance) but it should also work
hope this helps
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistaks.
|
|
|
|
|
Hello all!
I'm having a complicated problem here, here goes;
At my development workspace, im running on Vista, VB .net 2005 and the DB on SQL Express 2005. Now i would normally insert a date value as such;
INSERT INTO Table(DateColumn) VALUES ('" & "yyyymmdd" & '")
The date that is in yyyymmdd format without slashes in between, and its in a string format.
As far as it is, it works well.
But now my problem is, when I tried my program on another system (Windows XP), I couldnt be able to insert a date in such a way, an error states that 'unable to convert to smalldatetime ..etc'
ive' tried changing my method to as such,
INSERT INTO Table(DateColumn) VALUES (" & dateValue.Date & ")
it works, to most extent, but the weird part is, some areas in my program dint turn out to work as well as it's expected. The values are inserted into the DB but its showing "1/1/1900" ! As mentioned, using the same identical method on other areas dint have a problem.
What should I do? Why couldnt I in the first place, replicate the success I had over with my Vista workspace onto the other PC. (2 in fact, both running on XP).
Should I define how the database should accept date values? or?
Thanks in advance! Do need some advices here..
Regards,
Jensen
|
|
|
|
|
This is the problem with using string concantenation to build SQL query statements. Convert this to a parameterized query and you shouldn't have a problem with it at all.
Read SQL Injection Attacks[^] and it'll explain what a parameterized query is.
|
|
|
|
|
I know about creating parameterized queries but ive used it only at certains areas in my program.
I dint know its significant until now! It's really odd and I wouldn't have known if I dint come in here and asked!
Thanks once again!
|
|
|
|
|
Have you tried something like this:
INSERT INTO Table(DateColumn) VALUES (cast '" & "yyyymmdd" & '" as date)
You always pass failure on the way to success.
|
|
|
|
|
yes, but it works on some statements and wouldnt work the other half, its oddly strange but ive used the method specified by Dave ( see above ). It works, guess from now, ill just build all my statements using parameters.
but thanks for the suggestion!
|
|
|
|