Question:
Visual Basic Express 2010 Bold & Italic?
Wyatt
2012-05-23 18:35:16 UTC
I have a program where one check box makes the font bold and the other makes the text italic.

But if I click bold first then click italic, the bold will go away and not stay with the italic in the text.

I know I need more if statements and to use the & sign. But for some reason it isn't working...

Code:
If chkBold.Checked = True & chkItalic.Checked = True Then rtbInformation.Font = New Font("Franklin Gothic Medium", 10, _
FontStyle.Bold & FontStyle.Italic) _

f chkBold.Checked = True & chkItalic.Checked = False Then rtbInformation.Font = New Font("Franklin Gothic Medium", 10, _
FontStyle.Bold) _

Else rtbInformation.Font = New Font("Franklin Gothic Medium", 10, FontStyle.Regular)

Thanks! :]
Four answers:
Ratchetr
2012-05-23 19:27:26 UTC
You have 2 check boxes, so you have 4 combinations:

Not Bold, Not Italic

Not Bold, Italic

Bold, Not Italic

Bold, Italic



If you don't have 4 if else branches, then you don't have all the cases covered.



Rather than 4 calls to New Font, you would be better off with 1. And a variable to hold the FontStyle you want.



Something like this:



Dim fs As FontStyle = FontStyle.Regular



If chkBold.Checked Then

    fs = fs Or FontStyle.Bold

End If



If chkItalic.Checked Then

    fs = fs Or FontStyle.Italic

End If



rtbInformation.Font = New Font("Franklin Gothic Medium", 10,fs)



Although I said you need 4 if else branches, the code above does it with 2 if's and no else. But it still covers all 4 cases. Convince yourself of that, and you will get it ;-)
?
2016-10-19 01:14:23 UTC
i could say choose for 2010 first, through fact in spite of you have got a history in VB programming as quickly as you study VB6, you would be bowled over once you progression directly to 2010, as a outstanding factor of what you discovered from VB6 could be "out of date". (i've got did this till now from VB6 to 2008, and the diversities got here to me as a super ask your self), when you consider which you do no longer use ActiveX controls anymore - all controls and code are controlled via the .internet Framework, between some different issues. And plus, All domicile windows OSes have the .internet Framework put in, so the tip consumer would not could particularly acquire or set up something extra- different than this technique record/installer for this technique itself (except if the .internet Framework version is older than the single you're working this technique on - VB2008 helps as much as 3.5, and VB2010 is going as much as 4.0), the place through fact the older VB6 could require using a runtime library which could be used till now working this technique.
plutonic
2012-05-23 18:49:53 UTC
I don't know if you copied and pasted the code. I don't know if the second block is a separate if statement or it is an elseif. Also where is the endif?
CramShark.com
2012-05-23 18:45:19 UTC
Use Or



FontStyle.Bold Or FontStyle.Italic)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...