r/visualbasic • • Jul 02 '15

Making GUI, VBA needs to populate Excel sheet. I did all the work except this part, thought it would be cake. Is it even possible? First time using VBA. [Visual Studio 2012 + Office 2010]

5 Upvotes

So I'm making this GUI and I was under the impression the VBA could grab data from text boxes and put them in an excel sheet. After a lot of googling I'm getting the impression the VBA might not be able to do it, some show VB.Net can do it, others say I need to use some Microsoft add on / extension thing. Basically, I'm confused on what the real answer is. I did a lot of work already and I saved this for last because I thought it was going to be the easy part. I really don't want to start from scratch . Ideas? I'm using Visual Studio 2012 and Office 2010.


r/visualbasic • • Jun 06 '15

Article What's New in Visual Basic 14: ReadOnly Auto-Implemented Properties -- Visual Studio Magazine

Thumbnail
visualstudiomagazine.com
5 Upvotes

r/visualbasic • • Jun 04 '15

Solved Help me figure out a better way to make rounded corners for my forms.

5 Upvotes

I am building a open source them system for winforms, becuase all the ones that are good cost a lot of money.

I am making rounded corners on my form by using System.Drawing.Drawing2D and transparency key of Fuchsia. I used Fuchsia because it's ugly and if you make your form that color it is your own fault it will be transparent. :)

I am drawing the corners via bruteforce with the following code (This is only the upper right so you can imagine what it looks like for all the corners.)

G.FillRectangle(Brushes.Fuchsia, 0, 0, 1, 1)
G.FillRectangle(Brushes.Fuchsia, 1, 0, 1, 1)
G.FillRectangle(Brushes.Fuchsia, 2, 0, 1, 1)
G.FillRectangle(Brushes.Fuchsia, 3, 0, 1, 1)
G.FillRectangle(Brushes.Fuchsia, 0, 1, 1, 1)
G.FillRectangle(Brushes.Fuchsia, 0, 2, 1, 1)
G.FillRectangle(Brushes.Fuchsia, 0, 3, 1, 1)
G.FillRectangle(Brushes.Fuchsia, 1, 1, 1, 1)

G.FillRectangle(New SolidBrush(HeaderColor), 1, 3, 1, 1)
G.FillRectangle(New SolidBrush(HeaderColor), 1, 2, 1, 1)
G.FillRectangle(New SolidBrush(HeaderColor), 2, 1, 1, 1)
G.FillRectangle(New SolidBrush(HeaderColor), 3, 1, 1, 1)

does anybody know how I can draw the corners programmatically? I wish to do this so that I can make the corners size modifiable at design time.

I am investigating the GraphicsPath.AddPie and trying to figure out how to invert the image so that the corner edge is drawn but it is not working out.

Once this working and I am happy I will GitHub the whole thing with my tutorial, and post to here.


r/visualbasic • • May 26 '15

Homework /u/poody24 Asks a homework question...

5 Upvotes

I need to create a button that does this specifically, but I don't know the code to use. Add a button that will take the text that the user will enter into the txtName text box and place it into the label. The button will also make the text box and picture box disappear. Any Ideas??


r/visualbasic • • May 12 '15

VB.NET Help TableLayoutPanel woes

5 Upvotes

I'm using, or at least attempting to use a table layout panel on a form. The panel is being created dynamically at runtime as the contents of a tab. The tabs can be added and deleted by the user at runtime.

My issue is the contents of the panel are not showing up on the tab. They seem to be behind it and actually not bound by the borders of the tab.

The code...

    Private Sub PopulateTab(ByVal iTabPage As Integer)
    Dim txt As Label
    Dim grid As DataGridView
    Dim label As Label
    Dim iCol As Integer, iRow As Integer
    Dim panel As TableLayoutPanel

    'create the panel for layout
    panel = New TableLayoutPanel()
    panel.Name = "pnlSystemBodies" & iTabPage.ToString()
    panel.Location = New Point(3, 32)
    panel.Size = New Size(816, 250)

    panel.ColumnCount = 2
    panel.RowCount = 2
    panel.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 75.0F))
    panel.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 25.0F))
    panel.RowStyles.Add(New RowStyle(SizeType.Absolute, 20.0F))
    panel.RowStyles.Add(New RowStyle(SizeType.Percent, 100.0F))

    panel.Visible = True
    panel.Dock = DockStyle.Fill
    panel.Parent = tabSysBodies.TabPages(iTabPage)
    panel.Anchor = AnchorStyles.Top + AnchorStyles.Bottom + AnchorStyles.Left + AnchorStyles.Right

    'create a label for the primary type
    txt = New Label
    txt.Name = "txtPrimary" & iTabPage
    txt.Location = New Point(58, 38)
    txt.Parent = panel

    genSystem.primary(iTabPage).stellarAge = aiSysGen.GetStellarAge()
    genSystem.primary(iTabPage).spectrum = aiSysGen.GetSpectrum(genSystem.primary(iTabPage).stellarAge, iTabPage)

    txt.Text = genSystem.primary(iTabPage).spectrum
    txt.AutoSize = True

    'create a data grid for the orbital information
    grid = New DataGridView
    grid.Name = "grdSystem" & iTabPage
    grid.Location = New Point(78, 38)

    grid.Size = New Size(612, 215)
    grid.Visible = True
    grid.Parent = panel

    'add the controls to the layout grid
    panel.Controls.Add(txt, 0, 0)
    panel.Controls.Add(grid, 0, 1)

    With grid.Columns
        .Add("Orbit", "Orbit")
        .Add("Distance", "Distance")
        .Add("PType", "Type")
        .Add("Dia", "Diameter")
        .Add("Size", "Size")
        .Add("Gravity", "Gravity")
        .Add("Atmo", "Atmosphere")
        .Add("AtmoComp", "Atmospheric Composition")
        .Add("OI", "Organic Index")
        .Add("MI", "Mineral Index")
        .Add("Abundance", "Mineral Abundance")
        .Add("EIV", "Exploitation Index")
        .Add("Geo", "Geology")
        .Add("Hydro", "Hydrosphere")
        .Add("HydroPercent", "Hydro %")
        .Add("Bio", "Biosphere")
        .Add("Temp", "Temperature")

    End With

    Controls.Add(panel)

End Sub

Some of the code is experimental with me trying to figure out how to make the bloody thing work the way I want it to work. As it is, the code is also not complete. There are more controls to add it, but I see no point in doing that until I get the label and grid properly positioned.

Any one have any ideas on how to rectify this? I'll attach a screenshot in a moment.

Screenshot of the effect. https://www.dropbox.com/s/xgvyt03ql11hrb1/custom_system.PNG?dl=0


r/visualbasic • • May 12 '15

Web Server

5 Upvotes

I have a dedicated Minecraft server. I'd like to build a basic web server that shows detailed info about my server and let's me know if the Minecraft server process is running.

That way I don't have to keep an RDC window open while I play and so I can view stats when I'm away from home.

I've never built a web server app, so any tutorials or advice would be excellent.


r/visualbasic • • Apr 20 '15

Logging, do it or regret it later.

5 Upvotes

When a program starts getting ready for release to uses, it invariably happens that a developer thinks. We should probably have a log system so we know what happens when users use the machine. While this is correct it is way too late to be thinking about logging when the release is just around the corner.

This usually leads to a team member saying he can roll a logger in a "Couple of Hours". Which usually causes complete meltdown later on :)

I have a saying (#3 in my programmers list of programming) "Log early, and log often"

This means install your damn logging system early. I do this in my project creation step before the first commit to source control. Log often means log everything, albeit log important stuff with a higher level and the less import stuff lower down.

I have rolled my own logger, and in some cases still do if the project is an oddball. In most cases I use log4net. Log4net has been around a long time, has a great license (Apache License, Version 2.0) and is very easy to use in .NET.

It supports just about any type of logging you want;

Type										Description
-------------------------------------------------------------------------------------
log4net.Appender.AdoNetAppender				Writes logging events to a database using either prepared statements or stored procedures.
log4net.Appender.AnsiColorTerminalAppender	Writes color highlighted logging events to a an ANSI terminal window.
log4net.Appender.AspNetTraceAppender		Writes logging events to the ASP trace context. These can then be rendered at the end of the ASP page or on the ASP trace page.
log4net.Appender.ColoredConsoleAppender		Writes color highlighted logging events to the application's Windows Console.
log4net.Appender.ConsoleAppender			Writes logging events to the application's Console. The events may go to either the standard our stream or the standard error stream.
log4net.Appender.DebugAppender				Writes logging events to the .NET system.
log4net.Appender.EventLogAppender			Writes logging events to the Windows Event Log.
log4net.Appender.FileAppender				Writes logging events to a file in the file system.
log4net.Appender.LocalSyslogAppender		Writes logging events to the local syslog service (UNIX only).
log4net.Appender.MemoryAppender				Stores logging events in an in memory buffer.
log4net.Appender.NetSendAppender			Writes logging events to the Windows Messenger service. These messages are displayed in a dialog on a users terminal.
log4net.Appender.OutputDebugStringAppender	Writes logging events to the debugger. 
log4net.Appender.RemoteSyslogAppender		Writes logging events to a remote syslog service using UDP networking.
log4net.Appender.RemotingAppender			Writes logging events to a remoting sink using .NET remoting.
log4net.Appender.RollingFileAppender		Writes logging events to a file in the file system. The RollingFileAppender can be configured to log to multiple files based upon date or file size constraints.
log4net.Appender.SmtpAppender				Sends logging events to an email address.
log4net.Appender.SmtpPickupDirAppender		Sends logging events to an email address but writes the emails to a configurable directory rather than sending them directly via SMTP.
log4net.Appender.TelnetAppender				Clients connect via Telnet to receive logging events.
log4net.Appender.TraceAppender				Writes logging events to the .NET trace system.
log4net.Appender.UdpAppender				Sends logging events as connectionless UDP datagrams to a remote host or a multicast group using a UdpClient.

To use it is a simple as PIE, figure out what type of logging you want to do. I use Database logging for it makes it easier to query later, but it depends upon the project and info you need to log. Reference the log4net dll and do something like this;

Imports System

' Configure log4net using the .config file
<Assembly: log4net.Config.XmlConfigurator(Watch:=True)> 
' This will cause log4net to look for a configuration file
' called ConsoleApp.exe.config in the application base
' directory (i.e. the directory containing ConsoleApp.exe)

Namespace ConsoleApp
	' Example of how to simply configure and use log4net
	Public Class LoggingExample
		' Create a logger for use in this class
		Private Shared ReadOnly log As log4net.ILog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
		' NOTE that using System.Reflection.MethodBase.GetCurrentMethod().DeclaringType
		' is equivalent to typeof(LoggingExample) but is more portable
		' i.e. you can copy the code directly into another class without
		' needing to edit the code.

		' Application entry point
		Public Shared Sub Main(Byval args As String())
			' Log an info level message
			If log.IsInfoEnabled Then log.Info("Application [ConsoleApp] Start")

			' Log a debug message. Test if debug is enabled before
			' attempting to log the message. This is not required but
			' can make running without logging faster.
			If log.IsDebugEnabled Then log.Debug("This is a debug message")

			Try
				Bar()
			Catch ex As Exception
				' Log an error with an exception
				log.Error("Exception thrown from method Bar", ex)
			End Try

			log.Error("Hey this is an error!")

			Dim disposableFrame As IDisposable

			Try 
				' Push a message on to the Nested Diagnostic Context stack
				disposableFrame = log4net.NDC.Push("NDC_Message")

				log.Warn("This should have an NDC message")

				' Set a Mapped Diagnostic Context value  
				log4net.MDC.Set("auth", "auth-none")
				log.Warn("This should have an MDC message for the key 'auth'")
			Finally
				' The NDC message is popped off the stack by using the Dispose method
				If (Not disposableFrame is Nothing) Then disposableFrame.Dispose()
			End Try

			log.Warn("See the NDC has been popped of! The MDC 'auth' key is still with us.")

			' Log an info level message
			If log.IsInfoEnabled Then log.Info("Application [ConsoleApp] End")

			Console.Write("Press Enter to exit...")
			Console.ReadLine()
		End Sub

		' Helper methods to demonstrate location information and nested exceptions

		Private Shared Sub Bar()
			Goo()
		End Sub

		Private Shared Sub Foo()
			Throw new Exception("This is an Exception")
		End Sub

		Private Shared Sub Goo()
			Try
				Foo()
			Catch ex As Exception
				Throw New ArithmeticException("Failed in Goo. Calling Foo. Inner Exception provided", ex)
			End Try
		End Sub
	End Class

There are other loggers I just showed the one I am most familiar with (and the most commonly used) If you take anything away from this it should be "Log Early, and Log Often"

Bone


r/visualbasic • • Jun 03 '14

Your Favorite VB Namespace? ('Imports ...')

5 Upvotes

E.g: System.Math System.Net.Sockets


r/visualbasic • • Nov 26 '13

Inexperienced or Experienced, I need you.

5 Upvotes

I've been messing with VB.net since I could read the letters on the keyboard. I've got some fantastic ideas to manipulate the base into something great, but I can't do it single-handed. Is anyone on here down for some independent-contributions towards a group effort? Not paid, just for the challenge and fun.


r/visualbasic • • Apr 24 '13

Saving to a .txt file, and loading it to a list box.

5 Upvotes

I am doing a program where a user will enter a list of 10 endangered species and there scientific name, and then they can save if they wish to, here is my code

Option Explicit On Option Strict On Option Infer Off

Public Class Form1 Public strFileReader As String Public sreStreamReader As IO.StreamReader Public swrStreamWriter As IO.StreamWriter Public strNames(9) As String Public strFacts(9) As String Public TxtFile As IO.StreamWriter = IO.File.CreateText("endangered.txt") Public TxtFile2 As String = My.Computer.FileSystem.ReadAllText("endangered.txt") 'Public Forlstbx As String() = TxtFile2.Split(vbNewLine)

Private Sub mnuED_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuED.Click

    'Dim intEnter As Integer

    Dim intCounter As Integer = 0

    

    Do Until intCounter = 10
        strNames(intCounter) = InputBox("Input the name of the endangered animal", "Enter Name")
        If strNames(intCounter) = "" Then
            Exit Sub
        End If

        TxtFile.WriteLine(strNames(intCounter))

        lstbxEndangered.Items.Add(strNames(intCounter))
        strFacts(intCounter) = InputBox("Input the scientific name of the animal", "Sci name")
        If strFacts(intCounter) = "" Then
            Exit Sub
        End If
        TxtFile.WriteLine(strNames(intCounter))
        intCounter = intCounter + 1
    Loop



End Sub

Private Sub mnuRD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuRD.Click

    'when the user selects a item in the list box show the name 


    lblEndangeredSpeciesSciName.Text = (strFacts(lstbxEndangered.SelectedIndex))



End Sub

Private Sub mnuCD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCD.Click
    'clearing the data
    If MsgBox("Do you really want to clear all your data, your hard earned data? You REALLY want to delete all your data?", vbYesNo, "Clear Data") = vbYes Then
        Me.mnuCD.Visible = False
        Me.mnuRD.Visible = False
        Me.mnuWID.Visible = False
        Me.mnuCD.Enabled = False
        Me.mnuRD.Enabled = False
        Me.mnuWID.Enabled = False
        Me.mnuSD.Visible = False
        Me.mnuSD.Enabled = False
        Me.mnuED.Enabled = False
        Me.mnuED.Visible = False
        lstbxEndangered.Items.Clear()
        Me.lblEndangeredSpeciesSciName.Text = ""

    Else
        Me.mnuCD.Visible = False
        Me.mnuRD.Visible = False
        Me.mnuWID.Visible = False
        Me.mnuCD.Enabled = False
        Me.mnuRD.Enabled = False
        Me.mnuWID.Enabled = False
        Me.mnuSD.Enabled = False
        Me.mnuSD.Visible = False
    End If



End Sub

Private Sub mnuWID_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuWID.Click
    'help
    MessageBox.Show("This program will have you enter sciantific names of the endangered species of your choice. Then you can select them and see what the names are.", "WID")
End Sub

Private Sub mnuHTR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHTR.Click
    'help
    MessageBox.Show("When the program opens, hit 'Enter Data' this will bring you to a menu that will prompt you to enter names, then the sciantififc names of the animals. When all this is done, you can use the list box to select a animal then it's sciantific name will show.", "HTR")
End Sub

Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
    'close
    Me.Close()
End Sub

Private Sub FormLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'making only a few things visable, and checking if a .txt file exists
    Dim intcounter As Integer = 0
    Dim intsecondcounter As Integer = 0
    If IO.File.Exists("endangered.txt") Then
        If sreStreamReader.Peek() = -1 Then
            Me.mnuCD.Visible = False
            Me.mnuRD.Visible = False
            Me.mnuWID.Visible = False
            Me.mnuCD.Enabled = False
            Me.mnuRD.Enabled = False
            Me.mnuWID.Enabled = False
            Me.mnuSD.Visible = False
            Me.mnuSD.Enabled = False
            TxtFile.Close()
            Exit Sub
        End If

        sreStreamReader = IO.File.OpenText("endangered.txt")
        Do Until intsecondcounter = 10 OrElse sreStreamReader.Peek() = -1
            strNames(intsecondcounter) = sreStreamReader.ReadLine()
            strFacts(intsecondcounter) = sreStreamReader.ReadLine()

            intsecondcounter = intsecondcounter + 1
        Loop
        intcounter = 0
        intsecondcounter = 0
        Do Until intcounter = 10
            '  lstbxEndangered.Items.AddRange(Forlstbx)
            ' intcounter = intcounter + 1

        Loop
        Me.mnuCD.Visible = True
        Me.mnuRD.Visible = True
        Me.mnuWID.Visible = True
        Me.mnuCD.Enabled = True
        Me.mnuRD.Enabled = True
        Me.mnuWID.Enabled = True
        Me.mnuSD.Visible = True
        Me.mnuSD.Enabled = True
        Me.mnuED.Enabled = True
        Me.mnuED.Visible = True

    Else
        Me.mnuCD.Visible = False
        Me.mnuRD.Visible = False
        Me.mnuWID.Visible = False
        Me.mnuCD.Enabled = False
        Me.mnuRD.Enabled = False
        Me.mnuWID.Enabled = False
        Me.mnuSD.Visible = False
        Me.mnuSD.Enabled = False
    End If

End Sub

Private Sub mnuSD_Click(sender As System.Object, e As System.EventArgs) Handles mnuSD.Click
   

    TxtFile.Close()
    sreStreamReader.Close()

End Sub

End Class

but when i try to open, i get a message say no source available, and An error occurred creating the form. See Exception.InnerException for details. The error is: The process cannot access the file 'C:\Users\Mike\Downloads\EndangeredSpeciesSavedMike\EndangeredSpeciesSavedMike\EndangeredSpeciesMike\bin\Debug\endangered.txt' because it is being used by another process.

And I need to have it submitted by 2pm tomorrow, please help 0_0

Thank you, bigmikem2000.


r/visualbasic • • Apr 04 '13

Is there any website or such where you can post the entirety of your code without looking cluttered?

5 Upvotes

I know sometimes when i post on here I feel bad for posting my code, especially if its long. I feel like there must be some website out there that lets you either upload your code, or provide a means to get your code out there without it looking like a mess. I was thinking maybe a virtual compiler or something similar to google docs. I just think it might make it overall move easy if posters in the subreddit can simply post a link to their code rather than the whole code.


r/visualbasic • • Jun 08 '12

Need help with some coding time?

5 Upvotes

What I need the time output in a 24 hour output to look like: 07:53 or 14:34

What I have

Dim todaystime As Date

todaystime = Format(Now,"hh:mm")

what this outputs

3:00:00 AM

need:

03:00


r/visualbasic • • May 06 '12

Any online resources or books that include problems/projects?

5 Upvotes

I'm trying to teach myself VBA right now and I'm about half-way through Excel VBA Programming for Dummies. In my opinion, I don't think it's very good because there aren't very many problems/projects for me to try. Granted, I could think of my own projects, but can only think of so many different types.

All I'm looking for is a way to practice what I've learned. I have some programming experience with Python so it's been pretty learning the fundamentals (syntax, flow, etc.). I just would like some resource to provide for problems.