Maths Symbols in VB


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 15 of 15

Thread: Maths Symbols in VB

  1. #1
    Join Date
    Nov 2009
    Posts
    6

    Maths Symbols in VB

    Hi,
    I am fairly new to programming, so please bare with me. I want to program a Maths Quiz which allows the teacher to edit questions and solutions. But for

    For example, in a form I want to have a list of Maths symbols which can be chosen and the teacher can enter text around it. like 2(teacher selects symbol of root) and then enters 5.

    Please help me out I am falling behind the deadline for my coursework

  2. #2
    Join Date
    Nov 2009
    Posts
    6
    Anyone????

  3. #3
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  4. #4
    Join Date
    Feb 2004
    Location
    Longueuil, Québec
    Posts
    577
    There is a Symbol font that is usually installed on Windows computers (or maybe by Office) and that contains most of the mathematical symbols, including the greek letters that are also often used in mathematical expressions.

    Simply use that font and size it as necessary.

    The enclosed .gif attachment shows the content of the font.
    Attached Images Attached Images
    Jacques Bourgeois
    JBFI
    http://www3.sympatico.ca/jbfi/homeus.htm

  5. #5
    Join Date
    Nov 2009
    Posts
    7

    Display of maths symbols

    The symbols in a font appear in text streams and would not (without some programming) act as drivers for mathematical computations. If, as I understand it, you need a display mechanism for how formulas operate, you could try the following:

    Create a row of text boxes which will hold the parameters for your computation. One of them will hold a thumbnail picture of your maths symbol. At the top of the screen, you have a row of thumbnails with all required symbols. When you double-click on one of these it gets copied into the thumbnail in the formula. At the same time, a variable is set which indicates which computation is to be done. You then enter the appropriate numerical parameters and click on a compute key. This sets off some VBA code which (using a case statement on the computation type variable) computes and displays the answer.
    If you want to get really fancy and some symbols require different numbers of parameters, you can hide unwanted ones when you set the computation variable.
    I hope this helps.

  6. #6
    Join Date
    Nov 2009
    Posts
    6
    I managed the symbols but fractions are realllllllly confusing. I dont know how to implement them properly like done in word

  7. #7
    Join Date
    Feb 2004
    Location
    Longueuil, Québec
    Posts
    577
    If you are talking about the most standard fractions such as ½, ¼ and ¾, that appear automatically when you type 1/2, 1/4 and 3/4 in Word, they are part of most fonts. But you are limited to those 3 fractions. Word simply uses its AutoCorrect feature to replace what you type by the correct Ascii character.

    If you are talking about the Equation Editor in Word, it is something else. As far as I can tell, they draw the equations using GDI. It would be a lot of work to implement something akind to the Equation Editor.

    If you only need the divider line in a fraction, you can use a Line control. It is already available if you are in VB6, but has been thrown out of VB.NET.

    However, Microsoft has published a free package that brings back into .NET the missing controls from VB6, so you could get a Line control in .NET by downloading the Visual Basic Power Packs that should be easy to find on the Microsoft site.
    Jacques Bourgeois
    JBFI
    http://www3.sympatico.ca/jbfi/homeus.htm

  8. #8
    Join Date
    Nov 2009
    Posts
    6
    Anything that makes it look like a fraction, i.e. staright horizontal line between numerator and denominartor. and then treating it like a text, so that can be moved around easily. If GDi is the only way then how do i do it

  9. #9
    Join Date
    Feb 2004
    Location
    Longueuil, Québec
    Posts
    577
    GDI is a pain since you need to constantly redraw (repaint) everything you did each time the form is moved, resized, minimized, hidden, etc. Trying to work with existing controls is a lot easier since they do most of that for you.

    If you need only a straight horizontal line, the stuff might be very easy, depending on how the fraction is integrated with everything else in the equation, and you can go without GDI at all if you want.

    Look at the enclosed Image1 attachment. The thing is simply 2 Labels aligned vertically. I used an underlined font for the top one, adding spaces around the 3 (" 3 ") so that the underline is wide enough in relation to the bottom one. You can combine the 2 Labels in a User Control, so that when they move around as one.

    If you want to have more control over the divider, use a normal font and react to the Paint event of either of the Labels to draw a line. This is the simplest example of GDI you can find. This is the code that draws the line at the bottom of the top Label in Image2.

    Code:
    Private Sub Label1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Label1.Paint
    
        Dim pen As New Pen(Color.Black)
        e.Graphics.DrawLine(New Pen(Color.Black), 0, Label1.Height - 1, Label1.Width, Label1.Height - 1)
    
    End Sub
    I understand that you are new to programming, so a little advice : open your mind, be creative. Most "mortals" see programming as something that feels like maths. As an "immortal programmer" , I feel that it is more similar to art, where to have a set of tools (VB) and materials (controls, fonts) that you use together to build things out of your imagination. I have a background both in engineering and in arts, and I almost always feel that my art background is the one at play when I program.
    Attached Images Attached Images
    Jacques Bourgeois
    JBFI
    http://www3.sympatico.ca/jbfi/homeus.htm

  10. #10
    Join Date
    Nov 2009
    Posts
    6
    Quote Originally Posted by JBourgeois View Post

    If you need only a straight horizontal line, the stuff might be very easy, depending on how the fraction is integrated with everything else in the equation, and you can go without GDI at all if you want.

    Can I use the label method you suggested inside a textbox. this is the method i thought of.
    • The user presses a fraction button
    • a window comes up asking for numerator
    • The numerator is saved inside a label with underlined text
    • same goes for denominator without the underlined text
    • somehow i combine the two lables and make them appear in the rich textbox


    Will these two lables be able to move around as text.
    and how would I know the position of the cursor so that the labels go in the right place

  11. #11
    Join Date
    Feb 2004
    Location
    Longueuil, Québec
    Posts
    577
    Yes, a TextBox would work the same way, but you probably would have to change its BorderStyle property so that the line shows well. The default 3D border would probably make the thing look weird.

    If you want to move the combination around, design the combination as a UserControl. The UserControl is listed along Modules, Windows Forms, etc. when you add a New Item to a project. It is used to combine many controls into one.

    This creates a small surface akind to a form, but without borders. You put your two TextBoxes in the upper corner of the user control, making sure to resize the surface so that it just takes the amount of space you need, and add the code as if the 2 TextBoxes were on a Form. The result is a single control that incorporate the functionnality of 2 (or more when necessary)

    Once compiled, the UserControl should appears as a new control in your ToolBox. You can reuse it in any form you want as if it was a standard Control. The 2 TextBoxes are then seen as properties of the UserControl.

    To let the user move it around, you can enable Drag and Drop operations on the control. Drag and Drop is quite simple, but I do not have the time or space to describe all the little details here. It is covered extensively in online help if you simply select the entry for "drag and drop" in the index.

    Good luck
    Jacques Bourgeois
    JBFI
    http://www3.sympatico.ca/jbfi/homeus.htm

  12. #12
    Join Date
    Nov 2004
    Location
    Ottawa, ON, Canada
    Posts
    9

    Interesting problem

    When I first saw this thread, last Thursday or so, I thought this was an interesting problem to solve using a UserControl, since I hadn't really needed to do much with them.

    Attached is my attempt. It's not complete but it's close (maybe one of you other .Net UserControl geniuses can finish it).

    Anyway, it uses a "Fraction" class as the base data object for the User Control. The Fraction class has Numerator, Denominator and WholeNumber members, all Integers. There are two new methods, one that requires each part and one that parses a string that looks somewhat like "5 3/8". The UserControl doesn't have any explicit controls itself, instead everything is drawn on the UserControl surface. If the Fraction does not have a WholeNumber (i.e. it's Zero) then it won't try to show it (unless you set the property to make it do that). There's a bit of silly Font Metric stuff in there to figure out where to put everything.

    The Solution file opens up a test app that you can see in the attached image. I don't know why it's not working in the DataRepeater but I suspect it has something to do with a Paint event somewhere and/or the definition of the datasource. As you can see from the Debug output in the Immediate window it is generating random fractions.

    Someone else can add in Drag and Drop if they want. Unfortunately I can't spend anymore time on trying to fix this. Have fun.
    Attached Images Attached Images
    Attached Files Attached Files

  13. #13
    Join Date
    Feb 2004
    Location
    Longueuil, Québec
    Posts
    577
    A follow up on the PJCottan submission. I am overloaded and did not even have time to look at what he did, but I have a couple of minutes to react to "The UserControl doesn't have any explicit controls itself, instead everything is drawn on the UserControl surface".

    In such a case, it would be better to start from a Control Object ranther than a UserControl Object. The role of a UserContol is to be a container for other controls, with code to make them interact one with each other. If you do not put controls on it, you bring an unnecessary overhead.

    A Control however is a standalone thing. Since you draw on the surface, the same code (which I have not seen, I must repeat) that is used on the UserControl should normally draw the same thing on the Control, but end up with a leaner object.

    This is a common mistake, because "Control" is not offered when you add a new item to a project, a lot of people create UserControls white Controls would be more appropriate. You can easily create a simple Control by creating a new class and make in inherits from Control through code, as in the following.

    Code:
    Public Class MyControl
      Inherits System.Windows.Forms.Control
    
      'Use code similar to the one that is used to draw on the UserControl.
    
    End Class
    However, if the code provided works, there is an old saying in computer lingua: If it ain't broke, don't fix it.
    Jacques Bourgeois
    JBFI
    http://www3.sympatico.ca/jbfi/homeus.htm

  14. #14
    Join Date
    Nov 2004
    Location
    Ottawa, ON, Canada
    Posts
    9

    UserControl vs CustomControl

    I started out trying to place Labels and Line controls on a UserControl but found that the Label's lack of transparent background (in VB2008???) and its hidden extra padding, along with the fact that the Line is available only with the VB PowerPack forced me to abandon that midway. I still would have made the mistake of going with a UserControl even if I had started with the draw-only approach because that's what they seem to promote.

  15. #15
    Join Date
    Feb 2004
    Location
    Longueuil, Québec
    Posts
    577
    By default, Labels do not have a property that makes them transparents, and they do not react when to set their BackColor to Transparent.

    However, you can create a class that inherits from Label and uses CreateParams to enable transparency. Afterward, setting the BackColor to Transparent should work.
    Jacques Bourgeois
    JBFI
    http://www3.sympatico.ca/jbfi/homeus.htm

Similar Threads

  1. Told you so.... C# replacing VB
    By Bob in forum .NET
    Replies: 44
    Last Post: 06-06-2008, 04:39 AM
  2. re: moving from VB to C# -- more reasons
    By Jeff Johnson in forum .NET
    Replies: 6
    Last Post: 01-18-2007, 07:44 AM
  3. .NET vs. Enterprise Java: Who's Got Better Security?
    By Glen Kunene in forum Talk to the Editors
    Replies: 17
    Last Post: 03-23-2002, 12:43 AM
  4. Re: Writer's Uninformed Statements
    By Rich in forum .NET
    Replies: 38
    Last Post: 09-07-2001, 05:55 PM
  5. VB 6 does not get error from RAISERROR in SQL stored procdure
    By Allison Boughton in forum VB Classic
    Replies: 6
    Last Post: 03-05-2001, 12:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center