Hello,
Can someone tell me how I can randomly assign a file to a
variable from a directory.
Example:
Dim File as string
I need to search through 'C:/Comics/' and have the
program randomly pick a file from that path and assign it
to the variable 'File'
I will use this info to string together an image source
to randomly chage a picture. I am not interested in
using the ad rotator for this purpose.
Thanks. 3 1502
Hello,
"brian" <br****@lbrspec .com> schrieb: Can someone tell me how I can randomly assign a file to a variable from a directory.
Example: Dim File as string
I need to search through 'C:/Comics/' and have the program randomly pick a file from that path and assign it to the variable 'File'
I will use this info to string together an image source to randomly chage a picture. I am not interested in using the ad rotator for this purpose.
Untested:
\\\
Imports System.IO
..
..
..
Dim oRand As New Random(Environm ent.TickCount)
Dim files() As String = Directory.GetFi les("C:\")
Dim i As Integer = oRand.Next(0, files.Length - 1)
MsgBox(files(i) )
///
HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET http://www.mvps.org/dotnet
Thanks for the reply Tom.
Can you please explain something to me. What does
'Dim intNumber As Integer = CInt(rFile.Next Double() *
(strFiles.Lengt h -1))' Do?
I notice you assign this to an integer and the integer is
returned. How do you then tell the image source what
file name to use since you are not looking for a file
name but instead an integer? -----Original Message----- Hi, try this:
Imports System.IO .. .. .. Public Function GetRandomFile(B yVal strDirectory As
String) As String Dim strFiles() As String = Directory.GetFi les
(strDirectory) Dim rFile As New Random Dim intNumber As Integer = CInt(rFile.Next Double() *
(strFiles.Lengt h -1))
Return strFiles(intNum ber)
End Function
-- Happy to help, -- Tom Spink (th**********@ ntlworld.com)
"Go down with your server"
http://dotnetx.betasafe.com >> On The Mend
Please respond to the newsgroup, so all can benefit
"brian" <br****@lbrspec .com> wrote in message news:03******* *************** ******@phx.gbl. .. Hello,
Can someone tell me how I can randomly assign a file
to a variable from a directory.
Example: Dim File as string
I need to search through 'C:/Comics/' and have the program randomly pick a file from that path and assign
it to the variable 'File'
I will use this info to string together an image source to randomly chage a picture. I am not interested in using the ad rotator for this purpose.
Thanks.
.
"Tom Spink" <th**********@n tlworld.com> wrote in
news:ew******** *****@TK2MSFTNG P09.phx.gbl: Dim intNumber As Integer = CInt(rFile.Next Double() * (strFiles.Lengt h - 1))
The line above seems a little inefficient. You get a double from the
random generator and then convert it to an integer. Why not just get the
integer directly using the Next function?
Dim intNumber As Integer = rFile.Next(0,st rFiles.Length)
Just curious about the choice you made.
Chris This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: James M. |
last post by:
I have 2x Front-end Web servers (Win2003 Ent IIS6.0), setup with NLB (single
Affinity, also using SQLServer session state) that are hosting a few .NET ASP
web applications under the Default Website in IIS, and accessing via a
Intranet LAN (this is not publicly available).
NETWEB1:
NIC1 172.16.17.220
172.16.17.244 (NLB Virtual IP)
NIC2 172.16.17.221
|
by: Benny Ng |
last post by:
Hi,All,
Export Method:
-------------------------------------------------------------------------
strFileNameExport = "Results"
Response.Clear()
Response.Buffer = True
Response.ContentType ="application/vnd.ms-excel" 'application/msword
|
by: James |
last post by:
Just learning C#.
What's the easiest way to assign numbers 1-10 randomly to an array?
Basically I just want to take the numbers 1-10 and arrange them randomly in
slots 0-9 of an array.
Thanks
|
by: fbwhite |
last post by:
I know this issue has been brought up many times, but I have tried many of
the solutions to no avail. I wanted to give my specific case to see if
someone could be of any help.
We are using the sessionstate inproc mode and users are randomly losing
their session. I do not believe it is happening across all users at one
time. It seems to happen to different users at different times, but I am
only going off heresay. The aspnet worker...
|
by: TPK |
last post by:
I have an HTML document with Javascript where I have a portion of the
page contents, a series of questions, being pulled from a XML file.
When the page dynamically builds all the questions and selection
choices are listed top down in the order they appear in the XML file.
Here is an example of the XML formatting:
<question type="single_answer">The text of a question.
<answer correct="no">A. Answer One
<user_feedback>Incorrect...
| |
by: Alan Isaac |
last post by:
I need access to 2*n random choices for two types
subject to a constraint that in the end I have
drawn n of each. I first tried::
def random_types(n,typelist=):
types = typelist*n
random.shuffle(types)
for next_type in types:
yield next_type
|
by: rohit |
last post by:
hi,
i am developing a desktop search.For the index of the files i have
developed an algorithm with which
i should be able to read and write to a line if i know its line
number.
i can read a specified line by using the module linecache
but i am struck as to how to implement writing to the n(th) line in a
file EFFICIENTLY
which means i don't want to traverse the file sequentially to reach
the n(th) line
|
by: bb nicole |
last post by:
Hi.. i would like to create a page that provide users to randomly run phone number. I know it is use rand() to code it, but how if i porvide a box for user to key in how many phone number they want to key in?
For example, the user type 1000, then there are 1000 phone number will randomly run and come out as output.. And how to convert the result/output in .csv file? Thank a lot..:)
|
by: Man4ish |
last post by:
I have one pblm for reading a file randomly for searching the value with in given range.
e.g.
offset allele id
19 G/T 2066803
20 C/T 2066804
13 A/G 2066805
12 A/G 2066927
In the above file i have to search all the records which are in range (10,15). If i read whole file sequentially it will consume lot of time since data file is around 1GB. So I am planning...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |