Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET File I/O and Registry (http://www.xtremevbtalk.com/-net-file-i-o-and-registry/)
-   -   checking for folder - and advice needed (http://www.xtremevbtalk.com/-net-file-i-o-and-registry/328877-checking-folder-advice.html)

starmanMike 12-08-2017 04:36 AM

checking for folder - and advice needed
I have bitten the bullet and obtained VS2017 to update the app I wrote in VB6, thus I am an absolute beginner in .net! I have a startup form which needs to check for a couple of folders (which will be used later on) and if they don't exist they need to be created. In VB6 this was straightforward with declaring a FileSystemObject but in .net it seems to be different. What I have so far is this (I stsrted coding in .net literally yesterday!)

Imports System
Imports System.IO
Public Class frmStartup
    Private Sub frmStartup_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim obsfolder As String, chartsfolder As String
        obsfolder = Application.ExecutablePath & "\obs"
        chartsfolder = Application.ExecutablePath & "\charts"

        If System.IO.Directory.Exists(obsfolder) = False Then
        End If
        If System.IO.Directory.Exists(chartsfolder) = False Then
        End If

    End Sub
End Class

But when I run, I get the attached message in the immediate window:
Exception thrown: 'System.IO.IOException' in mscorlib.dll
The form appears but the folders are not created. I have made a virtual disk for my VS2017 projects.

Okay - since I am such a beginner I need a decent guide through the .net minefield. Can anyone suggest a book or tutorial? I have one from our local library but it doesn't cover everything I need for this project. It's "Beginning VB 2015" by Bryan Newsome.

Daigon Ali 12-08-2017 05:58 AM

'Application.ExecutablePath' includes the application's file name. Try using 'Application.StartupPath'.

starmanMike 12-08-2017 07:47 AM

Hi mate,
Thanks. That worked, and no error messages either!
But to prevent endless questions to this forum the point about books and tutorials remains, otherwise you guys will get fed up with me and my questions! ;-)

Daigon Ali 12-08-2017 09:02 AM

You're welcome.

I don't know about books but this site is quite useful and covers most versions of VB.
Visual Basic 2017 Tutorial - Visual Basic

I use SharpDevelop rather than VS but a few things that I soon discovered were:
  1. Brackets round all message boxes.
  2. The usual string functions Left,Right etc have to be "Microsoft.VisualBasic.Left" or you can import a reference e.g. "Imports VB = Microsoft.VisualBasic" so then you can just use "VB.Left".
  3. Syntax for a fields in an ADO recordset e.g. rs![my field] needs to be rs.Fields.Item("my field").value
  4. ADO isnull() is isDBNull()
  5. Year(Date) = Today.Year
  6. When formatting a date, the month has to be in upper case e.g. dd/MM/yy because mm donates minutes.
  7. Frame = Groupbox
  8. StatusBar = Statustrip
  9. MenuStrip instead of the menu editor.
  10. You have to save your code before you can run it even in the IDE.
  11. In a multi-select listbox, the listindex is always the first selected item.

starmanMike 12-17-2017 02:28 PM

Thanks for that, it will be very useful! I just discovered the 'microsoft.visualbasic' and status bar stuff yesterday, Also it seems that subroutine names have to start with uppercase.

All times are GMT -6. The time now is 11:22 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.