名称生成器没有文件路径 [英] Name Generator without file path

查看:78
本文介绍了名称生成器没有文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何通过在源代码中给出路径来生成不是来自txt文件的名称,但我希望名称应该在源代码中而不是给出路径。这是因为如果用户安装了我的软件,我还必须给他们名字文件,我不想这样做。那么有没有做那个头痛的部分?



这是我的代码:

Is there anyway to generate names not from the txt file by giving the path in the source code but i want the names should be in the source code instead of giving path. This is because if user installed my software, i also have to give them the names files, which i don't want to do that work. so is there anyway to do that headache part?

This is my code:

Private Function RandomLname(ByRef ranLname As String) As String

    Dim userPath As String = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
    Dim lname() As String
    Dim rand As New Random()
    lname = IO.File.ReadAllLines(userPath & "\Desktop\names\lastnames.txt")
    Return lname(rand.Next(0, lname.Length - 1))
    Return ranLname

End Function

推荐答案

一种方法是在项目中包含该文件:

在解决方案资源管理器窗格中打开项目,然后右键单击该项目。选择添加...现有项目

浏览到该文件(记住在对话框中选择文件类型)并将其插入到项目中。这会将文件复制到你的项目文件夹。

双击我的项目,然后从右侧的标签中选择资源。

拖动你的解压缩资源管理器中的文件并将其放在页面上。这将把它添加为资源。

关闭页面,并在解决方案资源管理器中突出显示该文件。

查看属性窗格,并将构建操作更改为嵌入式资源。

您现在可以将文件的全文添加到您的代码中:

One way to do it is to include the file in your project:
Open your project in the Solution Explorer pane, and right click the project. Select "Add...existing item"
Browse to the file (remembering to select the file type in the dialog) and insert it into your project. This will copy the file to your project folder.
Double click on "My Project", and select "Resources" from the tabs on the right hand side.
Drag your file from Solution Explorer and drop it on the page. This will add it as a resource.
Close the page, and highlight the file in Solution Explorer.
Look at the Properties pane, and change "Build Action" to "Embedded Resource".
You can now add the whole text of the file to your code with:
Dim data As String = My.Resources.NameOfTheFileWithoutTheExtension

并且文件将作为可执行文件的一部分包含在内。



请注意,这意味着您可以在编译之前更改文件,但是您无法更改它来自应用程序内容的内容。

And the file will be included as part of your executable.

Do note that this means you can change the file before compiling, but you can't change it's content from inside your application.


这篇关于名称生成器没有文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆